You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compiler/src/dotty/tools/backend/jvm/BCodeUtils.scala
+22-23Lines changed: 22 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -22,36 +22,35 @@ import scala.tools.asm
22
22
// (one can argue we should reuse one of the other existing helper objects, but that's for a later cleanup)
23
23
24
24
objectBCodeUtils {
25
-
valMAX_BYTES_PER_UTF8_CONSTANT=65535
26
-
/** Checks that the given signature if present, or the concatenation of the given name and descriptor, do not exceed the JVM's UTF-8 text size limits. */
// The JVM enforces a max length of 65535 bytes per UTF-8 constant.
29
-
// In practice the set of UTF-8 that Java uses can't be more than 4 bytes per char.
30
-
defcount(str: String, startAt: Int):Int=
31
-
varbyteCount= startAt
32
-
for
33
-
i <-0 until str.length
34
-
do
25
+
// The JVM enforces a max length of 65535 bytes per UTF-8 constant.
26
+
// Java uses "Modified UTF-8", in which the null character specifically is two bytes,
27
+
// and the rest of the BMP is as usual, see https://docs.oracle.com/javase/8/docs/api/java/io/DataInput.html#modified-utf-8
28
+
// Outside the BMP, characters are represented as surrogate pairs, i.e., 2+2 bytes, but `charAt` sees them as separate "characters".
29
+
// This means if we see a surrogate pair in a string, we should count each half as 2 bytes, since the encoded UTF-8 character will be 4 bytes.
30
+
// One consequence of this is that the maximum number of UTF-8 bytes for a single Java `char` (not codepoint!) is 3.
31
+
privatevalMAX_BYTES_PER_UTF8_CONSTANT=65535
32
+
privatevalMAX_BYTES_PER_CHAR=3
33
+
34
+
/** Checks that the given name, or the concatenation of the given two names and descriptor if present, do not exceed the JVM's UTF-8 text size limits. */
0 commit comments