Reviewers: Erik Corry, William Hesse,

Message:
Erik, William,

yes, I promised to fix ToCStrings methods, but having a closer look to those
noticed that logic is not quite simple, e.g. treatment of embedded 0,  
probably
UTF8 conversions (yes, ascii should be UTF8 and two bytes strings probably
should be UTF16).  And there is an explicit warning for those methods, so I
decided not to do a fast case (if destination and the string are of the same
kind, WriteToFlat), nor to flatten strings, but instead fixed two nasty  
callers
(keeping with contract of to C string methods).

Do you think it reasonable?  If not, would you mind if I just flatten  
strings in
to C string (depending on RobustFlag).

Description:
Use WriteToFlat instead of to C strings methods as WriteToFlat performs  
notably
better for various kinds of strings.


Please review this at http://codereview.chromium.org/293027

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/objects.cc


Index: src/objects.cc
===================================================================
--- src/objects.cc      (revision 3090)
+++ src/objects.cc      (working copy)
@@ -754,7 +754,8 @@
    if (FLAG_enable_slow_asserts) {
      // Assert that the resource and the string are equivalent.
      ASSERT(static_cast<size_t>(this->length()) == resource->length());
-    SmartPointer<uc16> smart_chars = this->ToWideCString();
+    SmartPointer<uc16> smart_chars(NewArray<uc16>(this->length()));
+    String::WriteToFlat(this, *smart_chars, 0, this->length());
      ASSERT(memcmp(*smart_chars,
                    resource->data(),
                    resource->length() * sizeof(**smart_chars)) == 0);
@@ -797,7 +798,8 @@
    if (FLAG_enable_slow_asserts) {
      // Assert that the resource and the string are equivalent.
      ASSERT(static_cast<size_t>(this->length()) == resource->length());
-    SmartPointer<char> smart_chars = this->ToCString();
+    SmartPointer<char> smart_chars(NewArray<char>(this->length()));
+    String::WriteToFlat(this, *smart_chars, 0, this->length());
      ASSERT(memcmp(*smart_chars,
                    resource->data(),
                    resource->length()*sizeof(**smart_chars)) == 0);



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to