Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Unified Diff: runtime/vm/symbols.cc

Issue 1323063004: Fix Dartium by supporting external strings as well in Symbols::FromConcatAll (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Formatting Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/symbols.cc
diff --git a/runtime/vm/symbols.cc b/runtime/vm/symbols.cc
index d8683fe7ab967f99998d6d50db5beeadb3725482..7106c7ab89b4f7575bdd074b5524061123047fec 100644
--- a/runtime/vm/symbols.cc
+++ b/runtime/vm/symbols.cc
@@ -394,14 +394,17 @@ RawString* Symbols::FromConcat(const String& str1, const String& str2) {
// TODO(srdjan): If this becomes performance critical code, consider looking
-// up symbol from pieces instead of concatenating them first into a big string.
+// up symbol from hash of pieces instead of concatenating them first into
+// a string.
RawString* Symbols::FromConcatAll(
const GrowableHandlePtrArray<const String>& strs) {
const intptr_t strs_length = strs.length();
GrowableArray<intptr_t> lengths(strs_length);
intptr_t len_sum = 0;
- bool is_one_byte_string = true;
+ const intptr_t kOneByteChar = 1;
+ intptr_t char_size = kOneByteChar;
+
for (intptr_t i = 0; i < strs_length; i++) {
const String& str = strs[i];
const intptr_t str_len = str.Length();
@@ -411,13 +414,11 @@ RawString* Symbols::FromConcatAll(
}
len_sum += str_len;
lengths.Add(str_len);
- if (!str.IsOneByteString()) {
- is_one_byte_string = false;
- }
+ char_size = Utils::Maximum(char_size, str.CharSize());
}
+ const bool is_one_byte_string = char_size == kOneByteChar;
Zone* zone = Thread::Current()->zone();
-
if (is_one_byte_string) {
uint8_t* buffer = zone->Alloc<uint8_t>(len_sum);
const uint8_t* const orig_buffer = buffer;
@@ -425,7 +426,10 @@ RawString* Symbols::FromConcatAll(
NoSafepointScope no_safepoint;
intptr_t str_len = lengths[i];
const String& str = strs[i];
siva 2015/09/02 18:06:44 ASSERT(str.IsOneByteString() || str.IsExternalOneB
srdjan 2015/09/02 18:24:37 Done.
- memmove(buffer, OneByteString::CharAddr(str, 0), str_len);
+ const uint8_t* src_p = str.IsOneByteString() ?
+ OneByteString::CharAddr(str, 0) :
+ ExternalOneByteString::CharAddr(str, 0);
+ memmove(buffer, src_p, str_len);
buffer += str_len;
}
ASSERT(len_sum == buffer - orig_buffer);
@@ -439,8 +443,14 @@ RawString* Symbols::FromConcatAll(
const String& str = strs[i];
if (str.IsTwoByteString()) {
memmove(buffer, TwoByteString::CharAddr(str, 0), str_len * 2);
+ } else if (str.IsExternalTwoByteString()) {
+ memmove(buffer, ExternalTwoByteString::CharAddr(str, 0), str_len * 2);
} else {
- uint8_t* src_p = OneByteString::CharAddr(str, 0);
+ // One-byte to two-byte string copy.
+ ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
+ const uint8_t* src_p = str.IsOneByteString() ?
+ OneByteString::CharAddr(str, 0) :
+ ExternalOneByteString::CharAddr(str, 0);
siva 2015/09/02 18:06:44 It might make sense to add a String::CharAddr(...)
srdjan 2015/09/02 18:24:37 String::CharAddr was removed because it caused con
for (int n = 0; n < str_len; n++) {
buffer[n] = src_p[n];
}
« no previous file with comments | « runtime/vm/object_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698