1 /* |
1 /* |
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
82 // The empty string contains nothing except the empty string. |
82 // The empty string contains nothing except the empty string. |
83 return -1; |
83 return -1; |
84 } |
84 } |
85 |
85 |
86 if (targetCount == 1) { |
86 if (targetCount == 1) { |
87 Pointer sourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED)); |
87 return AMD64ArrayIndexOf.indexOf1Char(source, sourceCount, totalOffset, target[targetOffset]); |
88 int indexOfResult = AMD64ArrayIndexOf.indexOf1Char(sourcePointer, sourceCount - fromIndex, target[targetOffset]); |
|
89 if (indexOfResult >= 0) { |
|
90 return indexOfResult + totalOffset; |
|
91 } |
|
92 return indexOfResult; |
|
93 } else if (targetCount == 2) { |
|
94 Pointer sourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED)); |
|
95 int indexOfResult = AMD64ArrayIndexOf.indexOfTwoConsecutiveChars(sourcePointer, sourceCount - fromIndex, target[targetOffset], target[targetOffset + 1]); |
|
96 if (indexOfResult >= 0) { |
|
97 return indexOfResult + totalOffset; |
|
98 } |
|
99 return indexOfResult; |
|
100 } else { |
88 } else { |
101 int haystackLength = sourceCount - (fromIndex + (targetCount - 2)); |
89 int haystackLength = sourceCount - (targetCount - 2); |
102 while (haystackLength > 0) { |
90 while (totalOffset < haystackLength) { |
103 Pointer sourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED)); |
91 int indexOfResult = AMD64ArrayIndexOf.indexOfTwoConsecutiveChars(source, haystackLength, totalOffset, target[targetOffset], target[targetOffset + 1]); |
104 int indexOfResult = AMD64ArrayIndexOf.indexOfTwoConsecutiveChars(sourcePointer, haystackLength, target[targetOffset], target[targetOffset + 1]); |
|
105 if (indexOfResult < 0) { |
92 if (indexOfResult < 0) { |
106 return -1; |
93 return -1; |
107 } |
94 } |
108 totalOffset += indexOfResult; |
95 totalOffset = indexOfResult; |
109 haystackLength -= (indexOfResult + 1); |
96 if (targetCount == 2) { |
110 Pointer cmpSourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED)); |
|
111 Pointer targetPointer = Word.objectToTrackedPointer(target).add(charArrayBaseOffset(INJECTED)).add(targetOffset * charArrayIndexScale(INJECTED)); |
|
112 if (ArrayRegionEqualsNode.regionEquals(cmpSourcePointer, targetPointer, targetCount, JavaKind.Char)) { |
|
113 return totalOffset; |
97 return totalOffset; |
|
98 } else { |
|
99 Pointer cmpSourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED)); |
|
100 Pointer targetPointer = Word.objectToTrackedPointer(target).add(charArrayBaseOffset(INJECTED)).add(targetOffset * charArrayIndexScale(INJECTED)); |
|
101 if (ArrayRegionEqualsNode.regionEquals(cmpSourcePointer, targetPointer, targetCount, JavaKind.Char)) { |
|
102 return totalOffset; |
|
103 } |
114 } |
104 } |
115 totalOffset++; |
105 totalOffset++; |
116 } |
106 } |
117 return -1; |
107 return -1; |
118 } |
108 } |
131 fromIndex = 0; |
121 fromIndex = 0; |
132 } |
122 } |
133 |
123 |
134 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { |
124 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { |
135 char[] sourceArray = StringSubstitutions.getValue(source); |
125 char[] sourceArray = StringSubstitutions.getValue(source); |
136 |
126 return AMD64ArrayIndexOf.indexOf1Char(sourceArray, sourceCount, fromIndex, (char) ch); |
137 Pointer sourcePointer = Word.objectToTrackedPointer(sourceArray).add(charArrayBaseOffset(INJECTED)).add(fromIndex * charArrayIndexScale(INJECTED)); |
|
138 int result = AMD64ArrayIndexOf.indexOf1Char(sourcePointer, sourceCount - fromIndex, (char) ch); |
|
139 if (result != -1) { |
|
140 return result + fromIndex; |
|
141 } |
|
142 return result; |
|
143 } else { |
127 } else { |
144 return indexOf(source, ch, origFromIndex); |
128 return indexOf(source, ch, origFromIndex); |
145 } |
129 } |
146 } |
130 } |
147 |
131 |