StringTracker::RecordWrite(str);
// Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters.
- str->TryFlattenIfNotFlat();
+ str->TryFlatten();
int end = length;
if ( (length == -1) || (length > str->length() - start) )
end = str->length() - start;
void FlattenString(Handle<String> string) {
- CALL_HEAP_FUNCTION_VOID(string->TryFlattenIfNotFlat());
+ CALL_HEAP_FUNCTION_VOID(string->TryFlatten());
ASSERT(string->IsFlat());
}
}
-Handle<String> SubString(Handle<String> str, int start, int end) {
- CALL_HEAP_FUNCTION(str->SubString(start, end), String);
+Handle<String> SubString(Handle<String> str,
+ int start,
+ int end,
+ PretenureFlag pretenure) {
+ CALL_HEAP_FUNCTION(str->SubString(start, end, pretenure), String);
}
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second);
-Handle<String> SubString(Handle<String> str, int start, int end);
+Handle<String> SubString(Handle<String> str,
+ int start,
+ int end,
+ PretenureFlag pretenure = NOT_TENURED);
// Sets the expected number of properties for the function's instances.
Object* Heap::AllocateSubString(String* buffer,
int start,
- int end) {
+ int end,
+ PretenureFlag pretenure) {
int length = end - start;
if (length == 1) {
}
// Make an attempt to flatten the buffer to reduce access time.
- if (!buffer->IsFlat()) {
- buffer->TryFlatten();
- }
+ buffer->TryFlatten();
Object* result = buffer->IsAsciiRepresentation()
- ? AllocateRawAsciiString(length)
- : AllocateRawTwoByteString(length);
+ ? AllocateRawAsciiString(length, pretenure )
+ : AllocateRawTwoByteString(length, pretenure);
if (result->IsFailure()) return result;
String* string_result = String::cast(result);
-
// Copy the characters into the new object.
if (buffer->IsAsciiRepresentation()) {
ASSERT(string_result->IsAsciiRepresentation());
// Please note this does not perform a garbage collection.
static Object* AllocateSubString(String* buffer,
int start,
- int end);
+ int end,
+ PretenureFlag pretenure = NOT_TENURED);
// Allocate a new external string object, which is backed by a string
// resource that resides outside the V8 heap.
}
-Object* String::TryFlattenIfNotFlat() {
+Object* String::TryFlatten(PretenureFlag pretenure) {
// We don't need to flatten strings that are already flat. Since this code
// is inlined, it can be helpful in the flat case to not call out to Flatten.
- if (!IsFlat()) {
- return TryFlatten();
- }
- return this;
+ if (IsFlat()) return this;
+ return SlowTryFlatten(pretenure);
}
}
-Object* String::TryFlatten() {
+Object* String::SlowTryFlatten(PretenureFlag pretenure) {
#ifdef DEBUG
// Do not attempt to flatten in debug mode when allocation is not
// allowed. This is to avoid an assertion failure when allocating.
// There's little point in putting the flat string in new space if the
// cons string is in old space. It can never get GCed until there is
// an old space GC.
- PretenureFlag tenure = Heap::InNewSpace(this) ? NOT_TENURED : TENURED;
+ PretenureFlag tenure = Heap::InNewSpace(this) ? pretenure : TENURED;
int len = length();
Object* object;
String* result;
}
// Try to flatten before operating on the string.
- name->TryFlattenIfNotFlat();
+ name->TryFlatten();
// Check if there is an API defined callback object which prohibits
// callback overwriting in this object or it's prototype chain.
// doesn't make Utf8Length faster, but it is very likely that
// the string will be accessed later (for example by WriteUtf8)
// so it's still a good idea.
- TryFlattenIfNotFlat();
+ TryFlatten();
Access<StringInputBuffer> buffer(&string_input_buffer);
buffer->Reset(0, this);
int result = 0;
}
-Object* String::SubString(int start, int end) {
+Object* String::SubString(int start, int end, PretenureFlag pretenure) {
if (start == 0 && end == length()) return this;
- Object* result = Heap::AllocateSubString(this, start, end);
+ Object* result = Heap::AllocateSubString(this, start, end, pretenure);
return result;
}
// Try to flatten the top level ConsString that is hiding behind this
// string. This is a no-op unless the string is a ConsString. Flatten
// mutates the ConsString and might return a failure.
- Object* TryFlatten();
+ Object* SlowTryFlatten(PretenureFlag pretenure);
// Try to flatten the string. Checks first inline to see if it is necessary.
- // Do not handle allocation failures. After calling TryFlattenIfNotFlat, the
+ // Do not handle allocation failures. After calling TryFlatten, the
// string could still be a ConsString, in which case a failure is returned.
// Use FlattenString from Handles.cc to be sure to flatten.
- inline Object* TryFlattenIfNotFlat();
+ inline Object* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
Vector<const char> ToAsciiVector();
Vector<const uc16> ToUC16Vector();
bool MarkAsUndetectable();
// Return a substring.
- Object* SubString(int from, int to);
+ Object* SubString(int from, int to, PretenureFlag pretenure = NOT_TENURED);
// String equality operations.
inline bool Equals(String* other);
Counters::total_parse_size.Increment(source->length());
// Initialize parser state.
- source->TryFlattenIfNotFlat();
+ source->TryFlatten();
scanner_.Init(source, stream, 0, JAVASCRIPT);
ASSERT(target_stack_ == NULL);
bool is_expression) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
HistogramTimerScope timer(&Counters::parse_lazy);
- source->TryFlattenIfNotFlat();
+ source->TryFlatten();
Counters::total_parse_size.Increment(source->length());
SafeStringInputBuffer buffer(source.location());
Counters::total_parse_size.Increment(source->length());
// Initialize parser state.
- source->TryFlattenIfNotFlat();
+ source->TryFlatten(TENURED);
scanner_.Init(source, stream, 0, JSON);
ASSERT(target_stack_ == NULL);
always_allow_natives_syntax = allow_natives_syntax_before;
// Parse the function by pulling the function source from the script source.
Handle<String> script_source(String::cast(script->source()));
+ Handle<String> function_source =
+ SubString(script_source, start_position, end_position, TENURED);
FunctionLiteral* result =
- parser.ParseLazy(SubString(script_source, start_position, end_position),
- name,
- start_position,
- is_expression);
+ parser.ParseLazy(function_source, name, start_position, is_expression);
return result;
}
int d = str1->Get(0) - str2->Get(0);
if (d != 0) return Smi::FromInt(d);
- str1->TryFlattenIfNotFlat();
- str2->TryFlattenIfNotFlat();
+ str1->TryFlatten();
+ str2->TryFlatten();
static StringInputBuffer buf1;
static StringInputBuffer buf2;
// string->Get(index).
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
if (index < static_cast<uint32_t>(string->length())) {
- string->TryFlattenIfNotFlat();
+ string->TryFlatten();
return LookupSingleCharacterStringFromCode(
string->Get(index));
}
result = SetElement(js_object, index, value);
} else {
Handle<String> key_string = Handle<String>::cast(key);
- key_string->TryFlattenIfNotFlat();
+ key_string->TryFlatten();
result = SetProperty(js_object, key_string, value, attr);
}
if (result.is_null()) return Failure::Exception();
return js_object->SetElement(index, *value);
} else {
Handle<String> key_string = Handle<String>::cast(key);
- key_string->TryFlattenIfNotFlat();
+ key_string->TryFlatten();
return js_object->IgnoreAttributesAndSetLocalProperty(*key_string,
*value,
attr);
key_string = Handle<String>::cast(converted);
}
- key_string->TryFlattenIfNotFlat();
+ key_string->TryFlatten();
return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION);
}
NoHandleAllocation ha;
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, subject, args[0]);
- subject->TryFlattenIfNotFlat();
+ subject->TryFlatten();
return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX));
}
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
- source->TryFlattenIfNotFlat();
+ source->TryFlatten();
int escaped_length = 0;
int length = source->length();
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
- source->TryFlattenIfNotFlat();
+ source->TryFlatten();
bool ascii = true;
int length = source->length();
CONVERT_CHECKED(String, s, args[0]);
CONVERT_SMI_CHECKED(radix, args[1]);
- s->TryFlattenIfNotFlat();
+ s->TryFlatten();
int len = s->length();
int i;
NoHandleAllocation ha;
CONVERT_CHECKED(String, s, args[0]);
- s->TryFlattenIfNotFlat();
+ s->TryFlatten();
int input_string_length = s->length();
// Assume that the string is not empty; we need this assumption later
CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]);
CONVERT_BOOLEAN_CHECKED(trimRight, args[2]);
- s->TryFlattenIfNotFlat();
+ s->TryFlatten();
int length = s->length();
int left = 0;
if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER);
- x->TryFlattenIfNotFlat();
- y->TryFlattenIfNotFlat();
+ x->TryFlatten();
+ y->TryFlatten();
return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
: StringInputBufferCompare(x, y);