111 }
112 }
113 return len1 - len2;
114 }
115
116 @HotSpotIntrinsicCandidate
117 public static int compareToUTF16(byte[] value, byte[] other) {
118 int len1 = length(value);
119 int len2 = StringUTF16.length(other);
120 int lim = Math.min(len1, len2);
121 for (int k = 0; k < lim; k++) {
122 char c1 = getChar(value, k);
123 char c2 = StringUTF16.getChar(other, k);
124 if (c1 != c2) {
125 return c1 - c2;
126 }
127 }
128 return len1 - len2;
129 }
130
131 public static int hashCode(byte[] value) {
132 int h = 0;
133 for (byte v : value) {
134 h = 31 * h + (v & 0xff);
135 }
136 return h;
137 }
138
139 public static int indexOf(byte[] value, int ch, int fromIndex) {
140 if (!canEncode(ch)) {
141 return -1;
142 }
143 int max = value.length;
144 if (fromIndex < 0) {
145 fromIndex = 0;
146 } else if (fromIndex >= max) {
147 // Note: fromIndex might be near -1>>>1.
148 return -1;
149 }
150 byte c = (byte)ch;
|
111 }
112 }
113 return len1 - len2;
114 }
115
116 @HotSpotIntrinsicCandidate
117 public static int compareToUTF16(byte[] value, byte[] other) {
118 int len1 = length(value);
119 int len2 = StringUTF16.length(other);
120 int lim = Math.min(len1, len2);
121 for (int k = 0; k < lim; k++) {
122 char c1 = getChar(value, k);
123 char c2 = StringUTF16.getChar(other, k);
124 if (c1 != c2) {
125 return c1 - c2;
126 }
127 }
128 return len1 - len2;
129 }
130
131 public static int compareToCI(byte[] value, byte[] other) {
132 int len1 = value.length;
133 int len2 = other.length;
134 int lim = Math.min(len1, len2);
135 for (int k = 0; k < lim; k++) {
136 if (value[k] != other[k]) {
137 char c1 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
138 char c2 = (char) CharacterDataLatin1.instance.toUpperCase(getChar(other, k));
139 if (c1 != c2) {
140 c1 = (char) CharacterDataLatin1.instance.toLowerCase(c1);
141 c2 = (char) CharacterDataLatin1.instance.toLowerCase(c2);
142 if (c1 != c2) {
143 return c1 - c2;
144 }
145 }
146 }
147 }
148 return len1 - len2;
149 }
150
151 public static int compareToCI_UTF16(byte[] value, byte[] other) {
152 int len1 = length(value);
153 int len2 = StringUTF16.length(other);
154 int lim = Math.min(len1, len2);
155 for (int k = 0; k < lim; k++) {
156 char c1 = getChar(value, k);
157 char c2 = StringUTF16.getChar(other, k);
158 if (c1 != c2) {
159 c1 = Character.toUpperCase(c1);
160 c2 = Character.toUpperCase(c2);
161 if (c1 != c2) {
162 c1 = Character.toLowerCase(c1);
163 c2 = Character.toLowerCase(c2);
164 if (c1 != c2) {
165 return c1 - c2;
166 }
167 }
168 }
169 }
170 return len1 - len2;
171 }
172
173 public static int hashCode(byte[] value) {
174 int h = 0;
175 for (byte v : value) {
176 h = 31 * h + (v & 0xff);
177 }
178 return h;
179 }
180
181 public static int indexOf(byte[] value, int ch, int fromIndex) {
182 if (!canEncode(ch)) {
183 return -1;
184 }
185 int max = value.length;
186 if (fromIndex < 0) {
187 fromIndex = 0;
188 } else if (fromIndex >= max) {
189 // Note: fromIndex might be near -1>>>1.
190 return -1;
191 }
192 byte c = (byte)ch;
|