Created
August 5, 2013 05:09
-
-
Save stevenschlansker/6153643 to your computer and use it in GitHub Desktop.
Java String intern() speedup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 2bfa00fac03f src/share/vm/classfile/javaClasses.cpp | |
--- a/src/share/vm/classfile/javaClasses.cpp Thu Jul 04 01:00:19 2013 -0700 | |
+++ b/src/share/vm/classfile/javaClasses.cpp Sun Aug 04 22:08:03 2013 -0700 | |
@@ -322,9 +322,7 @@ | |
jchar* result = NEW_RESOURCE_ARRAY_RETURN_NULL(jchar, length); | |
if (result != NULL) { | |
- for (int index = 0; index < length; index++) { | |
- result[index] = value->char_at(index + offset); | |
- } | |
+ value->char_cpy(result, offset, length); | |
} else { | |
THROW_MSG_0(vmSymbols::java_lang_OutOfMemoryError(), "could not allocate Unicode string"); | |
} | |
@@ -430,12 +428,8 @@ | |
if (length != len) { | |
return false; | |
} | |
- for (int i = 0; i < len; i++) { | |
- if (value->char_at(i + offset) != chars[i]) { | |
- return false; | |
- } | |
- } | |
- return true; | |
+ | |
+ return value->char_cmp(chars, offset, len) == 0; | |
} | |
void java_lang_String::print(Handle java_string, outputStream* st) { | |
diff -r 2bfa00fac03f src/share/vm/oops/typeArrayOop.hpp | |
--- a/src/share/vm/oops/typeArrayOop.hpp Thu Jul 04 01:00:19 2013 -0700 | |
+++ b/src/share/vm/oops/typeArrayOop.hpp Sun Aug 04 22:08:03 2013 -0700 | |
@@ -91,6 +91,21 @@ | |
return &char_base()[which]; | |
} | |
+ int char_cmp(jchar *to, size_t my_offset, size_t len) const { | |
+ if (len == 0) return 0; | |
+ assert(is_within_bounds(my_offset), "start index out of bounds"); | |
+ assert(is_within_bounds(my_offset + len - 1), "end index out of bounds"); | |
+ return memcmp(to, char_base() + my_offset, len * sizeof(jchar)); | |
+ } | |
+ | |
+ void char_cpy(jchar *to, size_t my_offset, size_t len) const { | |
+ if (len == 0) return; | |
+ assert(is_within_bounds(my_offset), "start index out of bounds"); | |
+ assert(is_within_bounds(my_offset + len - 1), "end index out of bounds"); | |
+ memcpy(to, char_base() + my_offset, len * sizeof(jchar)); | |
+ } | |
+ | |
+ | |
jint* int_at_addr(int which) const { | |
assert(is_within_bounds(which), "index out of bounds"); | |
return &int_base()[which]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment