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

Unified Diff: runtime/vm/dart_api_message.cc

Issue 11365243: Revert OneByteString back to ISO Latin-1 instead of ASCII (Closed) Base URL: http://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
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_message.cc
===================================================================
--- runtime/vm/dart_api_message.cc (revision 14982)
+++ 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)));
+ 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) {
+ uint8_t* latin1_str =
+ reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t)));
+ Utf8::DecodeToLatin1(utf8_str, utf8_len, latin1_str, len);
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 =
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698