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

Unified Diff: src/objects.cc

Issue 228093004: Implement handlified String::Flatten. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even shorter Created 6 years, 8 months 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 | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index d370e123380ba1d5a3cf2ab23005c94316621976..81aab909fe01a6148628a99f489eae5b462d2db2 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1182,6 +1182,34 @@ static bool AnWord(String* str) {
}
+Handle<String> String::SlowFlatten(Handle<ConsString> cons,
+ PretenureFlag pretenure) {
+ ASSERT(AllowHeapAllocation::IsAllowed());
+ ASSERT(cons->second()->length() != 0);
+ Isolate* isolate = cons->GetIsolate();
+ int length = cons->length();
+ PretenureFlag tenure = isolate->heap()->InNewSpace(*cons) ? pretenure
+ : TENURED;
+ Handle<SeqString> result;
+ if (cons->IsOneByteRepresentation()) {
+ Handle<SeqOneByteString> flat = isolate->factory()->NewRawOneByteString(
+ length, tenure).ToHandleChecked();
+ DisallowHeapAllocation no_gc;
+ WriteToFlat(*cons, flat->GetChars(), 0, length);
+ result = flat;
+ } else {
+ Handle<SeqTwoByteString> flat = isolate->factory()->NewRawTwoByteString(
+ length, tenure).ToHandleChecked();
+ DisallowHeapAllocation no_gc;
+ WriteToFlat(*cons, flat->GetChars(), 0, length);
+ result = flat;
+ }
+ cons->set_first(*result);
+ cons->set_second(isolate->heap()->empty_string());
+ return result;
+}
+
+
MaybeObject* String::SlowTryFlatten(PretenureFlag pretenure) {
#ifdef DEBUG
// Do not attempt to flatten in debug mode when allocation is not
@@ -6388,7 +6416,7 @@ void JSObject::DefineAccessor(Handle<JSObject> object,
AssertNoContextChange ncc(isolate);
// Try to flatten before operating on the string.
- if (name->IsString()) String::cast(*name)->TryFlatten();
+ if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
if (!JSObject::CanSetCallback(object, name)) return;
@@ -6576,7 +6604,7 @@ Handle<Object> JSObject::SetAccessor(Handle<JSObject> object,
AssertNoContextChange ncc(isolate);
// Try to flatten before operating on the string.
- if (name->IsString()) FlattenString(Handle<String>::cast(name));
+ if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
if (!JSObject::CanSetCallback(object, name)) {
return factory->undefined_value();
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698