> The string concatenation of java.base module is implemented based on > StringBuilder, which will result in extra object allocation and slow > performance. We can solve this problem by using String.concat method and > StringConcatHelper to provide concat method. > > for example, > > * use "+" > > class ClassDesc { > default String displayName() { > c.displayName() + "[]".repeat(depth) > } > } > > > bytecode: > > 106: new #40 // class java/lang/StringBuilder > 109: dup > 110: invokespecial #42 // Method > java/lang/StringBuilder."<init>":()V > 113: aload_2 > 114: invokeinterface #195, 1 // InterfaceMethod > displayName:()Ljava/lang/String; > 119: invokevirtual #50 // Method > java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; > 122: ldc #198 // String [] > 124: iload_1 > 125: invokevirtual #200 // Method > java/lang/String.repeat:(I)Ljava/lang/String; > 128: invokevirtual #50 // Method > java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; > 131: invokevirtual #53 // Method > java/lang/StringBuilder.toString:()Ljava/lang/String; > 134: areturn > > > * use String#concat > > c.displayName().concat("[]".repeat(depth)) > > > bytecode: > > 112: ldc #198 // String [] > 114: iload_1 > 115: invokevirtual #200 // Method > java/lang/String.repeat:(I)Ljava/lang/String; > 118: invokevirtual #86 // Method > java/lang/String.concat:(Ljava/lang/String;)Ljava/lang/String;
Shaojin Wen has updated the pull request incrementally with three additional commits since the last revision: - more concat - Suggestions from @ExE-Boss - concat Object value ------------- Changes: - all: https://git.openjdk.org/jdk/pull/20705/files - new: https://git.openjdk.org/jdk/pull/20705/files/16ec24a8..ea8c814e Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=20705&range=01 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=20705&range=00-01 Stats: 25 lines in 6 files changed: 7 ins; 7 del; 11 mod Patch: https://git.openjdk.org/jdk/pull/20705.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/20705/head:pull/20705 PR: https://git.openjdk.org/jdk/pull/20705