Commit e566c0f4 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Small clean up of externalizing strings.

R=verwaest@chromium.org

Review URL: https://codereview.chromium.org/462643002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23043 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d094d0fb
......@@ -5475,7 +5475,7 @@ Local<String> v8::String::NewExternal(
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 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
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 @@ bool v8::String::MakeExternal(
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 @@ bool v8::String::MakeExternal(
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);
......
......@@ -270,6 +270,7 @@ MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
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(),
......
......@@ -1052,11 +1052,10 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) {
resource->length() * sizeof(smart_chars[0])) == 0);
}
#endif // DEBUG
Heap* heap = GetHeap();
int size = this->Size(); // Byte size of the original string.
if (size < ExternalString::kShortSize) {
return false;
}
// Abort if size does not allow in-place conversion.
if (size < ExternalString::kShortSize) return false;
Heap* heap = GetHeap();
bool is_ascii = this->IsOneByteRepresentation();
bool is_internalized = this->IsInternalizedString();
......@@ -1109,6 +1108,9 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) {
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 @@ bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
resource->length() * sizeof(smart_chars[0])) == 0);
}
#endif // DEBUG
Heap* heap = GetHeap();
int size = this->Size(); // Byte size of the original string.
if (size < ExternalString::kShortSize) {
return false;
}
// Abort if size does not allow in-place conversion.
if (size < ExternalString::kShortSize) return false;
Heap* heap = GetHeap();
bool is_internalized = this->IsInternalizedString();
// Morph the string to an external string by replacing the map and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment