summaryrefslogtreecommitdiff
path: root/runtime/mirror/string.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/mirror/string.cc')
-rw-r--r--runtime/mirror/string.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc
index 839e01a045..2a26d50d79 100644
--- a/runtime/mirror/string.cc
+++ b/runtime/mirror/string.cc
@@ -37,10 +37,10 @@ namespace mirror {
int32_t String::FastIndexOf(int32_t ch, int32_t start) {
int32_t count = GetLength();
- if (start < 0) {
+ if (start >= count) {
+ return -1;
+ } else if (start < 0) {
start = 0;
- } else if (start > count) {
- start = count;
}
if (IsCompressed()) {
return FastIndexOf<uint8_t>(GetValueCompressed(), ch, start);
@@ -49,6 +49,18 @@ int32_t String::FastIndexOf(int32_t ch, int32_t start) {
}
}
+int32_t String::LastIndexOf(int32_t ch) {
+ int32_t count = GetLength();
+ if (count == 0) {
+ return -1;
+ }
+ if (IsCompressed()) {
+ return LastIndexOf<uint8_t>(GetValueCompressed(), ch, count - 1);
+ } else {
+ return LastIndexOf<uint16_t>(GetValue(), ch, count - 1);
+ }
+}
+
int32_t String::ComputeAndSetHashCode() {
int32_t new_hash_code = ComputeHashCode();
SetHashCode(new_hash_code);