Revision: 23043
Author:   [email protected]
Date:     Mon Aug 11 14:04:37 2014 UTC
Log:      Small clean up of externalizing strings.

[email protected]

Review URL: https://codereview.chromium.org/462643002
http://code.google.com/p/v8/source/detail?r=23043

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/factory.cc
 /branches/bleeding_edge/src/objects.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Mon Aug 11 14:00:58 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Mon Aug 11 14:04:37 2014 UTC
@@ -5475,7 +5475,7 @@
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
   i::Handle<i::String> obj = Utils::OpenHandle(this);
   i::Isolate* isolate = obj->GetIsolate();
-  if (i::StringShape(*obj).IsExternalTwoByte()) {
+  if (i::StringShape(*obj).IsExternal()) {
     return false;  // Already an external string.
   }
   ENTER_V8(isolate);
@@ -5488,6 +5488,8 @@
   CHECK(resource && resource->data());

   bool result = obj->MakeExternal(resource);
+ // Assert that if CanMakeExternal(), then externalizing actually succeeds.
+  DCHECK(!CanMakeExternal() || result);
   if (result) {
     DCHECK(obj->IsExternalString());
     isolate->heap()->external_string_table()->AddString(*obj);
@@ -5515,7 +5517,7 @@
     v8::String::ExternalAsciiStringResource* resource) {
   i::Handle<i::String> obj = Utils::OpenHandle(this);
   i::Isolate* isolate = obj->GetIsolate();
-  if (i::StringShape(*obj).IsExternalTwoByte()) {
+  if (i::StringShape(*obj).IsExternal()) {
     return false;  // Already an external string.
   }
   ENTER_V8(isolate);
@@ -5528,6 +5530,8 @@
   CHECK(resource && resource->data());

   bool result = obj->MakeExternal(resource);
+ // Assert that if CanMakeExternal(), then externalizing actually succeeds.
+  DCHECK(!CanMakeExternal() || result);
   if (result) {
     DCHECK(obj->IsExternalString());
     isolate->heap()->external_string_table()->AddString(*obj);
=======================================
--- /branches/bleeding_edge/src/factory.cc      Mon Aug 11 14:00:58 2014 UTC
+++ /branches/bleeding_edge/src/factory.cc      Mon Aug 11 14:04:37 2014 UTC
@@ -270,6 +270,7 @@
   int length = string.length();
   const uc16* start = string.start();
   if (String::IsOneByte(start, length)) {
+    if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
     Handle<SeqOneByteString> result;
     ASSIGN_RETURN_ON_EXCEPTION(
         isolate(),
=======================================
--- /branches/bleeding_edge/src/objects.cc      Mon Aug 11 14:00:58 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Mon Aug 11 14:04:37 2014 UTC
@@ -1052,11 +1052,10 @@
                   resource->length() * sizeof(smart_chars[0])) == 0);
   }
 #endif  // DEBUG
+  int size = this->Size();  // Byte size of the original string.
+  // Abort if size does not allow in-place conversion.
+  if (size < ExternalString::kShortSize) return false;
   Heap* heap = GetHeap();
-  int size = this->Size();  // Byte size of the original string.
-  if (size < ExternalString::kShortSize) {
-    return false;
-  }
   bool is_ascii = this->IsOneByteRepresentation();
   bool is_internalized = this->IsInternalizedString();

@@ -1109,6 +1108,9 @@


bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
+  // Externalizing twice leaks the external resource, so it's
+  // prohibited by the API.
+  DCHECK(!this->IsExternalString());
 #ifdef ENABLE_SLOW_DCHECKS
   if (FLAG_enable_slow_asserts) {
     // Assert that the resource and the string are equivalent.
@@ -1125,11 +1127,10 @@
                   resource->length() * sizeof(smart_chars[0])) == 0);
   }
 #endif  // DEBUG
+  int size = this->Size();  // Byte size of the original string.
+  // Abort if size does not allow in-place conversion.
+  if (size < ExternalString::kShortSize) return false;
   Heap* heap = GetHeap();
-  int size = this->Size();  // Byte size of the original string.
-  if (size < ExternalString::kShortSize) {
-    return false;
-  }
   bool is_internalized = this->IsInternalizedString();

   // Morph the string to an external string by replacing the map and

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to