Skip to content

Commit fec2ea0

Browse files
authored
Merge pull request #143 from mikezhang1234567890/string
Add initCompressionFlag() to String constructors
2 parents 1feac3d + f4378dd commit fec2ea0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/java.base/share/classes/java/lang/String.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ public String(int[] codePoints, int offset, int count) {
525525
this.value = val;
526526
return;
527527
}
528+
initCompressionFlag();
528529
}
529530
this.coder = UTF16;
530531
this.value = StringUTF16.toBytes(codePoints, offset, count);
@@ -589,6 +590,9 @@ public String(byte ascii[], int hibyte, int offset, int count) {
589590
}
590591
this.value = val;
591592
this.coder = UTF16;
593+
if (COMPACT_STRINGS) {
594+
initCompressionFlag();
595+
}
592596
}
593597
}
594598

@@ -822,6 +826,7 @@ public String(byte[] bytes, int offset, int length, Charset charset) {
822826
coder = LATIN1;
823827
return;
824828
}
829+
initCompressionFlag();
825830
}
826831
coder = UTF16;
827832
value = StringUTF16.toBytes(ca, 0, clen);
@@ -851,6 +856,9 @@ public String(byte[] bytes, int offset, int length, Charset charset) {
851856
coder = UTF16;
852857
value = StringUTF16.toBytes(ca, 0, caLen);
853858
}
859+
if (COMPACT_STRINGS && coder == UTF16) {
860+
initCompressionFlag();
861+
}
854862
}
855863

856864
/*
@@ -5262,7 +5270,8 @@ void getBytes(byte[] dst, int srcPos, int dstBegin, byte coder, int length) {
52625270
this.coder = LATIN1;
52635271
return;
52645272
}
5265-
}
5273+
initCompressionFlag();
5274+
}
52665275
this.coder = UTF16;
52675276
this.value = StringUTF16.toBytes(value, off, len);
52685277
}
@@ -5285,6 +5294,7 @@ void getBytes(byte[] dst, int srcPos, int dstBegin, byte coder, int length) {
52855294
this.value = buf;
52865295
return;
52875296
}
5297+
initCompressionFlag();
52885298
}
52895299
this.coder = UTF16;
52905300
this.value = Arrays.copyOfRange(val, 0, length << 1);

0 commit comments

Comments
 (0)