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

Unified Diff: runtime/vm/object.cc

Issue 11367044: Merged String subclasses into String. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index b3087fd40a9c181acc42f774c2eba4923cebf516..3b13ca55a988b279911360c71f446ade48b7a7e2 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -2191,20 +2191,19 @@ static bool MatchesAccessorName(const String& name,
RawFunction* Class::LookupFunction(const String& name) const {
Isolate* isolate = Isolate::Current();
ASSERT(name.IsOneByteString());
- const OneByteString& lookup_name = OneByteString::Cast(name);
Array& funcs = Array::Handle(isolate, functions());
if (funcs.IsNull()) {
// This can occur, e.g., for Null classes.
return Function::null();
}
Function& function = Function::Handle(isolate, Function::null());
- OneByteString& function_name =
- OneByteString::Handle(isolate, OneByteString::null());
+ String& function_name =
+ OneByteString::Handle(isolate, String::null());
Tom Ball 2012/11/02 23:31:50 Done.
intptr_t len = funcs.Length();
for (intptr_t i = 0; i < len; i++) {
function ^= funcs.At(i);
function_name ^= function.name();
- if (function_name.EqualsIgnoringPrivateKey(lookup_name)) {
+ if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) {
return function.raw();
}
}
@@ -2300,16 +2299,14 @@ RawField* Class::LookupStaticField(const String& name) const {
RawField* Class::LookupField(const String& name) const {
Isolate* isolate = Isolate::Current();
ASSERT(name.IsOneByteString());
- const OneByteString& lookup_name = OneByteString::Cast(name);
const Array& flds = Array::Handle(isolate, fields());
Field& field = Field::Handle(isolate, Field::null());
- OneByteString& field_name =
- OneByteString::Handle(isolate, OneByteString::null());
+ String& field_name = String::Handle(isolate, String::null());
intptr_t len = flds.Length();
for (intptr_t i = 0; i < len; i++) {
field ^= flds.At(i);
field_name ^= field.name();
- if (field_name.EqualsIgnoringPrivateKey(lookup_name)) {
+ if (OneByteString::EqualsIgnoringPrivateKey(field_name, name)) {
return field.raw();
}
}
@@ -9002,10 +8999,9 @@ RawInteger* Integer::New(const String& str, Heap::Space space) {
// We are not supposed to have integers represented as two byte or
// four byte strings.
ASSERT(str.IsOneByteString());
- const OneByteString& onestr = OneByteString::Cast(str);
int64_t value;
- if (!OS::StringToInt64(onestr.ToCString(), &value)) {
- const Bigint& big = Bigint::Handle(Bigint::New(onestr, space));
+ if (!OS::StringToInt64(str.ToCString(), &value)) {
+ const Bigint& big = Bigint::Handle(Bigint::New(str, space));
ASSERT(!BigintOperations::FitsIntoSmi(big));
ASSERT(!BigintOperations::FitsIntoMint(big));
return big.raw();
@@ -9770,16 +9766,48 @@ intptr_t String::Hash(const uint32_t* characters, intptr_t len) {
int32_t String::CharAt(intptr_t index) const {
- // String is an abstract class.
+ intptr_t class_id = raw()->GetClassId();
+ ASSERT(RawObject::IsStringClassId(class_id));
+ switch (class_id) {
+ case kOneByteStringCid:
+ return *OneByteString::CharAddr(*this, index);
+ case kTwoByteStringCid:
+ return *TwoByteString::CharAddr(*this, index);
+ case kExternalOneByteStringCid:
+ return *ExternalOneByteString::CharAddr(*this, index);
+ case kExternalTwoByteStringCid:
+ return *ExternalTwoByteString::CharAddr(*this, index);
+ }
UNREACHABLE();
return 0;
}
intptr_t String::CharSize() const {
- // String is an abstract class.
- UNREACHABLE();
- return 0;
+ intptr_t class_id = raw()->GetClassId();
+ if (class_id == kOneByteStringCid || class_id == kExternalOneByteStringCid) {
+ return kOneByteChar;
+ }
+ ASSERT(class_id == kTwoByteStringCid ||
+ class_id == kExternalTwoByteStringCid);
+ return kTwoByteChar;
+}
+
+
+bool String::IsExternal() const {
+ intptr_t class_id = raw()->GetClassId();
+ return class_id == kExternalOneByteStringCid ||
+ class_id == kExternalTwoByteStringCid;
+}
+
+
+void* String::GetPeer() const {
+ intptr_t class_id = raw()->GetClassId();
+ if (class_id == kExternalOneByteStringCid) {
+ return ExternalOneByteString::GetPeer(*this);
+ }
+ ASSERT(class_id == kExternalTwoByteStringCid);
+ return ExternalTwoByteString::GetPeer(*this);
}
@@ -9925,19 +9953,19 @@ RawString* String::New(const uint8_t* utf8_array,
Utf8::Type type;
intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type);
if (type == Utf8::kAscii) {
- const OneByteString& strobj
- = OneByteString::Handle(OneByteString::New(len, space));
+ const String& strobj = String::Handle(OneByteString::New(len, space));
if (len > 0) {
NoGCScope no_gc;
- Utf8::DecodeToAscii(utf8_array, array_len, strobj.CharAddr(0), len);
+ Utf8::DecodeToAscii(utf8_array, array_len,
+ OneByteString::CharAddr(strobj, 0), len);
}
return strobj.raw();
}
ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
- const TwoByteString& strobj =
- TwoByteString::Handle(TwoByteString::New(len, space));
+ const String& strobj = String::Handle(TwoByteString::New(len, space));
NoGCScope no_gc;
- Utf8::DecodeToUTF16(utf8_array, array_len, strobj.CharAddr(0), len);
+ Utf8::DecodeToUTF16(utf8_array, array_len,
+ TwoByteString::CharAddr(strobj, 0), len);
return strobj.raw();
}
@@ -10023,16 +10051,17 @@ void String::Copy(const String& dst, intptr_t dst_offset,
ASSERT(len >= 0);
ASSERT(len <= (dst.Length() - dst_offset));
if (dst.IsOneByteString()) {
- const OneByteString& onestr = OneByteString::Cast(dst);
NoGCScope no_gc;
if (len > 0) {
- memmove(onestr.CharAddr(dst_offset), characters, len);
+ memmove(OneByteString::CharAddr(dst, dst_offset),
+ characters,
+ len);
}
} else if (dst.IsTwoByteString()) {
- const TwoByteString& twostr = TwoByteString::Cast(dst);
NoGCScope no_gc;
+ uint16_t* dst_chars = TwoByteString::CharAddr(dst, dst_offset);
for (intptr_t i = 0; i < len; ++i) {
- *twostr.CharAddr(i + dst_offset) = characters[i];
+ dst_chars[i] = characters[i];
}
}
}
@@ -10045,18 +10074,19 @@ void String::Copy(const String& dst, intptr_t dst_offset,
ASSERT(array_len >= 0);
ASSERT(array_len <= (dst.Length() - dst_offset));
if (dst.IsOneByteString()) {
- const OneByteString& onestr = OneByteString::Cast(dst);
NoGCScope no_gc;
+ uint8_t* dst_chars = OneByteString::CharAddr(dst, dst_offset);
for (intptr_t i = 0; i < array_len; ++i) {
ASSERT(utf16_array[i] <= 0x7F);
- *onestr.CharAddr(i + dst_offset) = utf16_array[i];
+ dst_chars[i + dst_offset] = utf16_array[i];
}
} else {
ASSERT(dst.IsTwoByteString());
- const TwoByteString& twostr = TwoByteString::Cast(dst);
NoGCScope no_gc;
if (array_len > 0) {
- memmove(twostr.CharAddr(dst_offset), utf16_array, (array_len * 2));
+ memmove(TwoByteString::CharAddr(dst, dst_offset),
+ utf16_array,
+ array_len * 2);
}
}
}
@@ -10074,26 +10104,34 @@ void String::Copy(const String& dst, intptr_t dst_offset,
intptr_t char_size = src.CharSize();
if (char_size == kOneByteChar) {
if (src.IsOneByteString()) {
- const OneByteString& onestr = OneByteString::Cast(src);
NoGCScope no_gc;
- String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len);
+ String::Copy(dst,
+ dst_offset,
+ OneByteString::CharAddr(src, src_offset),
+ len);
} else {
ASSERT(src.IsExternalOneByteString());
- const ExternalOneByteString& onestr = ExternalOneByteString::Cast(src);
NoGCScope no_gc;
- String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len);
+ String::Copy(dst,
+ dst_offset,
+ ExternalOneByteString::CharAddr(src, src_offset),
+ len);
}
} else {
ASSERT(char_size == kTwoByteChar);
if (src.IsTwoByteString()) {
- const TwoByteString& twostr = TwoByteString::Cast(src);
NoGCScope no_gc;
- String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len);
+ String::Copy(dst,
+ dst_offset,
+ TwoByteString::CharAddr(src, src_offset),
+ len);
} else {
ASSERT(src.IsExternalTwoByteString());
- const ExternalTwoByteString& twostr = ExternalTwoByteString::Cast(src);
NoGCScope no_gc;
- String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len);
+ String::Copy(dst,
+ dst_offset,
+ ExternalTwoByteString::CharAddr(src, src_offset),
+ len);
}
}
}
@@ -10102,12 +10140,10 @@ void String::Copy(const String& dst, intptr_t dst_offset,
RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) {
if (str.IsOneByteString()) {
- const OneByteString& onestr = OneByteString::Cast(str);
- return onestr.EscapeSpecialCharacters(raw_str);
+ return OneByteString::EscapeSpecialCharacters(str, raw_str);
}
ASSERT(str.IsTwoByteString());
- const TwoByteString& twostr = TwoByteString::Cast(str);
- return twostr.EscapeSpecialCharacters(raw_str);
+ return TwoByteString::EscapeSpecialCharacters(str, raw_str);
}
@@ -10224,10 +10260,10 @@ const char* String::ToCString() const {
void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const {
if (CharSize() == kOneByteChar) {
- const OneByteString& obj = OneByteString::Cast(*this);
+ const String& obj = *this;
ASSERT(array_len >= obj.Length());
if (obj.Length() > 0) {
- memmove(utf8_array, obj.CharAddr(0), obj.Length());
+ memmove(utf8_array, OneByteString::CharAddr(obj, 0), obj.Length());
}
} else {
ASSERT(array_len >= Utf8::Length(*this));
@@ -10275,41 +10311,44 @@ RawString* String::ToLowerCase(const String& str, Heap::Space space) {
}
-RawOneByteString* OneByteString::EscapeSpecialCharacters(bool raw_str) const {
- intptr_t len = Length();
+RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str,
+ bool raw_str) {
+ intptr_t len = str.Length();
if (len > 0) {
intptr_t num_escapes = 0;
intptr_t index = 0;
+ uint8_t* str_chars = CharAddr(str, 0);
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(i)) ||
- (!raw_str && (*CharAddr(i) == '\\'))) {
+ if (IsSpecialCharacter(str_chars[i]) ||
+ (!raw_str && (str_chars[i] == '\\'))) {
Tom Ball 2012/11/02 23:31:50 The code was getting uglier and harder to understa
num_escapes += 1;
}
}
- const OneByteString& dststr = OneByteString::Handle(
+ const String& dststr = String::Handle(
OneByteString::New(len + num_escapes, Heap::kNew));
+ uint8_t* dst_chars = CharAddr(dststr, 0);
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(i))) {
- *(dststr.CharAddr(index)) = '\\';
- *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i));
+ if (IsSpecialCharacter(str_chars[i])) {
+ dst_chars[index] = '\\';
+ dst_chars[index + 1] = SpecialCharacter(str_chars[i]);
index += 2;
- } else if (!raw_str && (*CharAddr(i) == '\\')) {
- *(dststr.CharAddr(index)) = '\\';
- *(dststr.CharAddr(index + 1)) = '\\';
+ } else if (!raw_str && (str_chars[i] == '\\')) {
+ dst_chars[index] = '\\';
+ dst_chars[index + 1] = '\\';
index += 2;
} else {
- *(dststr.CharAddr(index)) = *CharAddr(i);
+ dst_chars[index] = str_chars[i];
index += 1;
}
}
- return dststr.raw();
+ return reinterpret_cast<RawOneByteString*>(dststr.raw());
}
return OneByteString::null();
}
-// Check to see if 'name' matches 'this' as is or
-// once the private key separator is stripped from name.
+// Check to see if 'str1' matches 'str2' as is or
+// once the private key separator is stripped from str2.
//
// Things are made more complicated by the fact that constructors are
// added *after* the private suffix, so "foo@123.named" should match
@@ -10319,46 +10358,49 @@ RawOneByteString* OneByteString::EscapeSpecialCharacters(bool raw_str) const {
//
// _ReceivePortImpl@6be832b._internal@6be832b
//
-bool OneByteString::EqualsIgnoringPrivateKey(const OneByteString& name) const {
- if (raw() == name.raw()) {
+bool OneByteString::EqualsIgnoringPrivateKey(const String& str1,
+ const String& str2) {
+ if (str1.raw() == str2.raw()) {
return true; // Both handles point to the same raw instance.
}
- intptr_t len = Length();
- intptr_t name_len = name.Length();
- if (len == name_len) {
+ intptr_t len = str1.Length();
+ intptr_t str2_len = str2.Length();
+ uint8_t* str1_chars = CharAddr(str1, 0);
+ uint8_t* str2_chars = CharAddr(str2, 0);
+ if (len == str2_len) {
for (intptr_t i = 0; i < len; i++) {
- if (*(CharAddr(i)) != *(name.CharAddr(i))) {
+ if (str1_chars[i] != str2_chars[i]) {
return false;
}
}
return true;
}
- if (len < name_len) {
+ if (len < str2_len) {
return false; // No way they can match.
}
intptr_t pos = 0;
- intptr_t name_pos = 0;
+ intptr_t str2_pos = 0;
while (pos < len) {
- int32_t ch = *(CharAddr(pos));
+ int32_t ch = str1_chars[pos];
pos++;
if (ch == Scanner::kPrivateKeySeparator) {
// Consume a private key separator.
- while (pos < len && *(CharAddr(pos)) != '.') {
+ while ((pos < len) && (str1_chars[pos] != '.')) {
pos++;
}
// Resume matching characters.
continue;
}
- if (name_pos == name_len || ch != *(name.CharAddr(name_pos))) {
+ if ((str2_pos == str2_len) || (ch != str2_chars[str2_pos])) {
return false;
}
- name_pos++;
+ str2_pos++;
}
// We have reached the end of mangled_name string.
ASSERT(pos == len);
- return (name_pos == name_len);
+ return (str2_pos == str2_len);
}
@@ -10371,9 +10413,9 @@ RawOneByteString* OneByteString::New(intptr_t len,
// This should be caught before we reach here.
FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len);
}
- OneByteString& result = OneByteString::Handle();
+ String& result = String::Handle();
{
- RawObject* raw = Object::Allocate(OneByteString::kClassId,
+ RawObject* raw = Object::Allocate(kClassId,
OneByteString::InstanceSize(len),
space);
NoGCScope no_gc;
@@ -10381,56 +10423,54 @@ RawOneByteString* OneByteString::New(intptr_t len,
result.SetLength(len);
result.SetHash(0);
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
RawOneByteString* OneByteString::New(const uint8_t* characters,
intptr_t len,
Heap::Space space) {
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result = String::Handle(OneByteString::New(len, space));
if (len > 0) {
NoGCScope no_gc;
- memmove(result.CharAddr(0), characters, len);
+ memmove(CharAddr(result, 0), characters, len);
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
RawOneByteString* OneByteString::New(const uint16_t* characters,
intptr_t len,
Heap::Space space) {
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result =String::Handle(OneByteString::New(len, space));
+ uint8_t* dst_chars = CharAddr(result, 0);
for (intptr_t i = 0; i < len; ++i) {
ASSERT(characters[i] <= 0x7F);
- *result.CharAddr(i) = characters[i];
+ dst_chars[i] = characters[i];
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
RawOneByteString* OneByteString::New(const uint32_t* characters,
intptr_t len,
Heap::Space space) {
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result =String::Handle(OneByteString::New(len, space));
+ uint8_t* dst_chars = CharAddr(result, 0);
for (intptr_t i = 0; i < len; ++i) {
ASSERT(characters[i] <= 0x7F);
- *result.CharAddr(i) = characters[i];
+ dst_chars[i] = characters[i];
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
RawOneByteString* OneByteString::New(const OneByteString& str,
Heap::Space space) {
intptr_t len = str.Length();
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result = String::Handle(OneByteString::New(len, space));
String::Copy(result, 0, str, 0, len);
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
@@ -10440,20 +10480,18 @@ RawOneByteString* OneByteString::Concat(const String& str1,
intptr_t len1 = str1.Length();
intptr_t len2 = str2.Length();
intptr_t len = len1 + len2;
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result = String::Handle(OneByteString::New(len, space));
String::Copy(result, 0, str1, 0, len1);
String::Copy(result, len1, str2, 0, len2);
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
RawOneByteString* OneByteString::ConcatAll(const Array& strings,
intptr_t len,
Heap::Space space) {
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
- OneByteString& str = OneByteString::Handle();
+ const String& result = String::Handle(OneByteString::New(len, space));
+ String& str = String::Handle();
intptr_t strings_len = strings.Length();
intptr_t pos = 0;
for (intptr_t i = 0; i < strings_len; i++) {
@@ -10462,7 +10500,7 @@ RawOneByteString* OneByteString::ConcatAll(const Array& strings,
String::Copy(result, pos, str, 0, str_len);
pos += str_len;
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
@@ -10471,50 +10509,48 @@ RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
Heap::Space space) {
ASSERT(!str.IsNull());
intptr_t len = str.Length();
- const OneByteString& result =
- OneByteString::Handle(OneByteString::New(len, space));
+ const String& result = String::Handle(OneByteString::New(len, space));
+ uint8_t* dst_chars = CharAddr(result, 0);
for (intptr_t i = 0; i < len; ++i) {
int32_t ch = mapping(str.CharAt(i));
ASSERT(ch >= 0 && ch <= 0x7F);
- *result.CharAddr(i) = ch;
+ dst_chars[i] = ch;
}
- return result.raw();
+ return reinterpret_cast<RawOneByteString*>(result.raw());
}
-const char* OneByteString::ToCString() const {
- return String::ToCString();
-}
-
-
-RawTwoByteString* TwoByteString::EscapeSpecialCharacters(bool raw_str) const {
- intptr_t len = Length();
+RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str,
+ bool raw_str) {
+ intptr_t len = str.Length();
if (len > 0) {
intptr_t num_escapes = 0;
intptr_t index = 0;
+ uint16_t* str_chars = CharAddr(str, 0);
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(i)) ||
- (!raw_str && (*CharAddr(i) == '\\'))) {
+ if (IsSpecialCharacter(str_chars[i]) ||
+ (!raw_str && (str_chars[i] == '\\'))) {
Tom Ball 2012/11/02 23:31:50 Restored.
num_escapes += 1;
}
}
- const TwoByteString& dststr = TwoByteString::Handle(
+ const String& dststr = String::Handle(
TwoByteString::New(len + num_escapes, Heap::kNew));
+ uint16_t* dst_chars = CharAddr(dststr, 0);
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(i))) {
- *(dststr.CharAddr(index)) = '\\';
- *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i));
+ if (IsSpecialCharacter(str_chars[i])) {
Tom Ball 2012/11/02 23:31:50 Restored.
Tom Ball 2012/11/02 23:31:50 Restored.
+ dst_chars[index] = '\\';
+ dst_chars[index + 1] = SpecialCharacter(str_chars[i]);
index += 2;
- } else if (!raw_str && (*CharAddr(i) == '\\')) {
- *(dststr.CharAddr(index)) = '\\';
- *(dststr.CharAddr(index + 1)) = '\\';
+ } else if (!raw_str && (str_chars[i] == '\\')) {
+ dst_chars[index] = '\\';
+ dst_chars[index + 1] = '\\';
index += 2;
} else {
- *(dststr.CharAddr(index)) = *CharAddr(i);
+ dst_chars[index] = str_chars[i];
index += 1;
}
}
- return dststr.raw();
+ return reinterpret_cast<RawTwoByteString*>(dststr.raw());
}
return TwoByteString::null();
}
@@ -10527,9 +10563,9 @@ RawTwoByteString* TwoByteString::New(intptr_t len,
// This should be caught before we reach here.
FATAL1("Fatal error in TwoByteString::New: invalid len %"Pd"\n", len);
}
- TwoByteString& result = TwoByteString::Handle();
+ String& result = String::Handle();
{
- RawObject* raw = Object::Allocate(TwoByteString::kClassId,
+ RawObject* raw = Object::Allocate(kClassId,
TwoByteString::InstanceSize(len),
space);
NoGCScope no_gc;
@@ -10537,7 +10573,7 @@ RawTwoByteString* TwoByteString::New(intptr_t len,
result.SetLength(len);
result.SetHash(0);
}
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
@@ -10545,13 +10581,12 @@ RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array,
intptr_t array_len,
Heap::Space space) {
ASSERT(array_len > 0);
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(array_len, space));
+ const String& result = String::Handle(TwoByteString::New(array_len, space));
{
NoGCScope no_gc;
- memmove(result.CharAddr(0), utf16_array, (array_len * 2));
+ memmove(CharAddr(result, 0), utf16_array, (array_len * 2));
}
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
@@ -10560,34 +10595,33 @@ RawTwoByteString* TwoByteString::New(intptr_t utf16_len,
intptr_t array_len,
Heap::Space space) {
ASSERT((array_len > 0) && (utf16_len >= array_len));
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(utf16_len, space));
+ const String& result = String::Handle(TwoByteString::New(utf16_len, space));
{
NoGCScope no_gc;
intptr_t j = 0;
+ uint16_t* dst = CharAddr(result, 0);
for (intptr_t i = 0; i < array_len; ++i) {
if (utf32_array[i] > 0xffff) {
ASSERT(j < (utf16_len - 1));
- Utf8::ConvertUTF32ToUTF16(utf32_array[i], result.CharAddr(j));
+ Utf8::ConvertUTF32ToUTF16(utf32_array[i], &dst[j]);
j += 2;
} else {
ASSERT(j < utf16_len);
- *result.CharAddr(j) = utf32_array[i];
+ dst[j] = utf32_array[i];
j += 1;
}
}
}
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
RawTwoByteString* TwoByteString::New(const TwoByteString& str,
Heap::Space space) {
intptr_t len = str.Length();
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(len, space));
+ const String& result = String::Handle(TwoByteString::New(len, space));
String::Copy(result, 0, str, 0, len);
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
@@ -10597,19 +10631,17 @@ RawTwoByteString* TwoByteString::Concat(const String& str1,
intptr_t len1 = str1.Length();
intptr_t len2 = str2.Length();
intptr_t len = len1 + len2;
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(len, space));
+ const String& result = String::Handle(TwoByteString::New(len, space));
String::Copy(result, 0, str1, 0, len1);
String::Copy(result, len1, str2, 0, len2);
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
RawTwoByteString* TwoByteString::ConcatAll(const Array& strings,
intptr_t len,
Heap::Space space) {
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(len, space));
+ const String& result = String::Handle(TwoByteString::New(len, space));
String& str = String::Handle();
intptr_t strings_len = strings.Length();
intptr_t pos = 0;
@@ -10619,7 +10651,7 @@ RawTwoByteString* TwoByteString::ConcatAll(const Array& strings,
String::Copy(result, pos, str, 0, str_len);
pos += str_len;
}
- return result.raw();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
@@ -10628,19 +10660,14 @@ RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch),
Heap::Space space) {
ASSERT(!str.IsNull());
intptr_t len = str.Length();
- const TwoByteString& result =
- TwoByteString::Handle(TwoByteString::New(len, space));
+ const String& result = String::Handle(TwoByteString::New(len, space));
+ uint16_t* dst_chars = CharAddr(result, 0);
for (intptr_t i = 0; i < len; ++i) {
int32_t ch = mapping(str.CharAt(i));
ASSERT(ch >= 0 && ch <= 0xFFFF);
- *result.CharAddr(i) = ch;
+ dst_chars[i] = ch;
}
- return result.raw();
-}
-
-
-const char* TwoByteString::ToCString() const {
- return String::ToCString();
+ return reinterpret_cast<RawTwoByteString*>(result.raw());
}
@@ -10664,28 +10691,28 @@ RawExternalOneByteString* ExternalOneByteString::New(
void* peer,
Dart_PeerFinalizer callback,
Heap::Space space) {
- ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() !=
- Class::null());
+ ASSERT(Isolate::Current()->object_store()->
+ external_one_byte_string_class() != Class::null());
if (len < 0 || len > kMaxElements) {
// This should be caught before we reach here.
FATAL1("Fatal error in ExternalOneByteString::New: invalid len %"Pd"\n",
len);
}
- ExternalOneByteString& result = ExternalOneByteString::Handle();
+ String& result = String::Handle();
ExternalStringData<uint8_t>* external_data =
new ExternalStringData<uint8_t>(data, peer, callback);
{
- RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId,
+ RawObject* raw = Object::Allocate(kClassId,
ExternalOneByteString::InstanceSize(),
space);
NoGCScope no_gc;
result ^= raw;
result.SetLength(len);
result.SetHash(0);
- result.SetExternalData(external_data);
+ SetExternalData(result, external_data);
}
AddFinalizer(result, external_data, ExternalOneByteString::Finalize);
- return result.raw();
+ return reinterpret_cast<RawExternalOneByteString*>(result.raw());
}
@@ -10705,11 +10732,6 @@ void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) {
}
-const char* ExternalOneByteString::ToCString() const {
- return String::ToCString();
-}
-
-
RawExternalTwoByteString* ExternalTwoByteString::New(
const uint16_t* data,
intptr_t len,
@@ -10723,21 +10745,21 @@ RawExternalTwoByteString* ExternalTwoByteString::New(
FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %"Pd"\n",
len);
}
- ExternalTwoByteString& result = ExternalTwoByteString::Handle();
+ String& result = String::Handle();
ExternalStringData<uint16_t>* external_data =
new ExternalStringData<uint16_t>(data, peer, callback);
{
- RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId,
+ RawObject* raw = Object::Allocate(kClassId,
ExternalTwoByteString::InstanceSize(),
space);
NoGCScope no_gc;
result ^= raw;
result.SetLength(len);
result.SetHash(0);
- result.SetExternalData(external_data);
+ SetExternalData(result, external_data);
}
AddFinalizer(result, external_data, ExternalTwoByteString::Finalize);
- return result.raw();
+ return reinterpret_cast<RawExternalTwoByteString*>(result.raw());
}
@@ -10747,11 +10769,6 @@ void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) {
}
-const char* ExternalTwoByteString::ToCString() const {
- return String::ToCString();
-}
-
-
RawBool* Bool::True() {
return Isolate::Current()->object_store()->true_value();
}

Powered by Google App Engine
This is Rietveld 408576698