Chromium Code Reviews| Index: runtime/vm/dart_api_message.cc |
| =================================================================== |
| --- runtime/vm/dart_api_message.cc (revision 14917) |
| +++ runtime/vm/dart_api_message.cc (working copy) |
| @@ -347,13 +347,22 @@ |
| intptr_t len = ReadSmiValue(); |
| intptr_t hash = ReadSmiValue(); |
| USE(hash); |
| - Dart_CObject* object = AllocateDartCObjectString(len); |
| + uint8_t *latin1 = |
| + reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); |
|
Søren Gjesse
2012/11/15 08:11:30
It would be nice if we could avoid the additional
siva
2012/11/15 22:42:59
I agree that we can do some optimization here for
|
| + intptr_t utf8_len = 0; |
| + for (intptr_t i = 0; i < len; i++) { |
| + latin1[i] = Read<uint8_t>(); |
| + utf8_len += Utf8::Length(latin1[i]); |
| + } |
| + Dart_CObject* object = AllocateDartCObjectString(utf8_len); |
| AddBackRef(object_id, object, kIsDeserialized); |
| char* p = object->value.as_string; |
| for (intptr_t i = 0; i < len; i++) { |
| - p[i] = Read<uint8_t>(); |
| + p += Utf8::Encode(latin1[i], p); |
| } |
| - p[len] = '\0'; |
| + *p = '\0'; |
| + ASSERT(p == (object->value.as_string + utf8_len)); |
| + ::free(latin1); |
| return object; |
| } |
| case kTwoByteStringCid: { |
| @@ -376,7 +385,7 @@ |
| p += Utf8::Encode(utf16[i], p); |
| } |
| *p = '\0'; |
| - ASSERT(p == object->value.as_string + utf8_len); |
| + ASSERT(p == (object->value.as_string + utf8_len)); |
| ::free(utf16); |
| return object; |
| } |
| @@ -772,16 +781,20 @@ |
| // Write out the serialization header value for this object. |
| WriteInlinedHeader(object); |
| // Write out the class and tags information. |
| - WriteIndexedObject(type == Utf8::kAscii ? kOneByteStringCid |
| - : kTwoByteStringCid); |
| + WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid |
| + : kTwoByteStringCid); |
| WriteIntptrValue(0); |
| // Write string length, hash and content |
| WriteSmi(len); |
| WriteSmi(0); // TODO(sgjesse): Hash - not written. |
| - if (type == Utf8::kAscii) { |
| + if (type == Utf8::kLatin1) { |
|
Søren Gjesse
2012/11/15 08:11:30
It would be nice if Utf8::CodePointCount could als
siva
2012/11/15 22:42:59
Yes, this was an optimization I was planning on do
|
| + uint8_t* latin1_str = |
| + reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); |
| + Utf8::DecodeToLatin1(utf8_str, utf8_len, latin1_str, len); |
|
Søren Gjesse
2012/11/15 08:11:30
If the Utf8 class had a function to convert a sing
siva
2012/11/15 22:42:59
Good point, would like to do this in a new CL in o
|
| for (intptr_t i = 0; i < len; i++) { |
| - Write<uint8_t>(utf8_str[i]); |
| + Write<uint8_t>(latin1_str[i]); |
| } |
| + ::free(latin1_str); |
| } else { |
| // TODO(sgjesse): Make sure surrogate pairs are handled. |
| uint16_t* utf16_str = |