Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index f25f106c3a0ca8e11e0d3a6daef9e46e0c15172f..df62a758552e301c633970bb53914b00696a70b0 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -13244,8 +13244,18 @@ RawString* String::EscapeSpecialCharacters(const String& str) { |
| if (str.IsOneByteString()) { |
| return OneByteString::EscapeSpecialCharacters(str); |
| } |
| - ASSERT(str.IsTwoByteString()); |
| - return TwoByteString::EscapeSpecialCharacters(str); |
| + if (str.IsTwoByteString()) { |
| + return TwoByteString::EscapeSpecialCharacters(str); |
| + } |
| + if (str.IsExternalOneByteString()) { |
| + return ExternalOneByteString::EscapeSpecialCharacters(str); |
| + } |
| + ASSERT(str.IsExternalTwoByteString()); |
| + // If EscapeSpecialCharacters is frequently called on external two byte |
| + // strings, we should implement it directly on ExternalTwoByteString rather |
| + // than first converting to a TwoByteString. |
| + return TwoByteString::EscapeSpecialCharacters( |
| + String::Handle(TwoByteString::New(str, Heap::kNew))); |
| } |
| @@ -13673,6 +13683,35 @@ RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) { |
| return OneByteString::null(); |
| } |
| +RawOneByteString* ExternalOneByteString::EscapeSpecialCharacters( |
| + const String& str) { |
| + intptr_t len = str.Length(); |
| + if (len > 0) { |
| + intptr_t num_escapes = 0; |
| + intptr_t index = 0; |
|
hausner
2013/09/30 22:54:37
declare index just before the loop below where it'
Jacob
2013/09/30 23:53:28
Fixed that here and in the code this method was co
|
| + for (intptr_t i = 0; i < len; i++) { |
| + if (IsSpecialCharacter(*CharAddr(str, i))) { |
| + num_escapes += 1; |
| + } |
| + } |
| + const String& dststr = String::Handle( |
| + OneByteString::New(len + num_escapes, Heap::kNew)); |
| + for (intptr_t i = 0; i < len; i++) { |
| + if (IsSpecialCharacter(*CharAddr(str, i))) { |
| + *(OneByteString::CharAddr(dststr, index)) = '\\'; |
| + *(OneByteString::CharAddr(dststr, index + 1)) = |
| + SpecialCharacter(*CharAddr(str, i)); |
| + index += 2; |
| + } else { |
| + *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); |
| + index += 1; |
| + } |
| + } |
| + return OneByteString::raw(dststr); |
| + } |
| + return OneByteString::null(); |
|
hausner
2013/09/30 22:54:37
It it correct to return null when the input string
Jacob
2013/09/30 23:53:28
That is what the existing code did but I agree it
|
| +} |
| + |
| RawOneByteString* OneByteString::New(intptr_t len, |
| Heap::Space space) { |