Author: [email protected]
Date: Mon Jan 26 00:35:41 2009
New Revision: 1142
Modified:
branches/bleeding_edge/src/api.cc
branches/bleeding_edge/src/handles.cc
branches/bleeding_edge/src/jsregexp.cc
branches/bleeding_edge/src/objects-inl.h
branches/bleeding_edge/src/objects.cc
branches/bleeding_edge/src/objects.h
branches/bleeding_edge/src/parser.cc
branches/bleeding_edge/src/runtime.cc
Log:
Fix bug where strings were not flattened before regexp.
Review URL: http://codereview.chromium.org/18552
Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc (original)
+++ branches/bleeding_edge/src/api.cc Mon Jan 26 00:35:41 2009
@@ -2017,7 +2017,7 @@
i::Handle<i::String> str = Utils::OpenHandle(this);
// Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters.
- str->TryFlatten(i::StringShape(*str));
+ str->TryFlattenIfNotFlat(i::StringShape(*str));
int end = length;
if ( (length == -1) || (length > str->length() - start) )
end = str->length() - start;
@@ -2042,7 +2042,7 @@
i::Handle<i::String> str = Utils::OpenHandle(this);
// Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters.
- str->TryFlatten(i::StringShape(*str));
+ str->TryFlattenIfNotFlat(i::StringShape(*str));
int end = length;
if ( (length == -1) || (length > str->length() - start) )
end = str->length() - start;
Modified: branches/bleeding_edge/src/handles.cc
==============================================================================
--- branches/bleeding_edge/src/handles.cc (original)
+++ branches/bleeding_edge/src/handles.cc Mon Jan 26 00:35:41 2009
@@ -188,7 +188,7 @@
void FlattenString(Handle<String> string) {
StringShape shape(*string);
if (string->IsFlat(shape)) return;
- CALL_HEAP_FUNCTION_VOID(string->Flatten(shape));
+ CALL_HEAP_FUNCTION_VOID(string->TryFlatten(shape));
ASSERT(string->IsFlat(StringShape(*string)));
}
Modified: branches/bleeding_edge/src/jsregexp.cc
==============================================================================
--- branches/bleeding_edge/src/jsregexp.cc (original)
+++ branches/bleeding_edge/src/jsregexp.cc Mon Jan 26 00:35:41 2009
@@ -697,7 +697,7 @@
Handle<String> pattern(re->Pattern());
StringShape shape(*pattern);
if (!pattern->IsFlat(shape)) {
- pattern->Flatten(shape);
+ FlattenString(pattern);
}
RegExpCompileData compile_data;
@@ -824,7 +824,7 @@
Handle<Object> matches;
if (!subject->IsFlat(shape)) {
- subject->Flatten(shape);
+ FlattenString(subject);
}
while (true) {
@@ -920,6 +920,7 @@
offsets_vector,
previous_index == 0);
} else { // Sequential string
+ ASSERT(StringShape(*subject).IsSequential());
Address char_address =
is_ascii ? SeqAsciiString::cast(*subject)->GetCharsAddress()
: SeqTwoByteString::cast(*subject)->GetCharsAddress();
Modified: branches/bleeding_edge/src/objects-inl.h
==============================================================================
--- branches/bleeding_edge/src/objects-inl.h (original)
+++ branches/bleeding_edge/src/objects-inl.h Mon Jan 26 00:35:41 2009
@@ -1431,13 +1431,14 @@
}
-void String::TryFlatten(StringShape shape) {
+Object* String::TryFlattenIfNotFlat(StringShape shape) {
ASSERT(shape.type() == StringShape(this).type());
// 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(shape)) {
- Flatten(shape);
+ return TryFlatten(shape);
}
+ return this;
}
Modified: branches/bleeding_edge/src/objects.cc
==============================================================================
--- branches/bleeding_edge/src/objects.cc (original)
+++ branches/bleeding_edge/src/objects.cc Mon Jan 26 00:35:41 2009
@@ -587,7 +587,7 @@
}
-Object* String::Flatten(StringShape shape) {
+Object* String::TryFlatten(StringShape shape) {
#ifdef DEBUG
// Do not attempt to flatten in debug mode when allocation is not
// allowed. This is to avoid an assertion failure when allocating.
@@ -604,11 +604,11 @@
// SlicedStrings.
String* buf = ss->buffer();
ASSERT(!buf->IsSlicedString());
- Object* ok = buf->Flatten(StringShape(buf));
+ Object* ok = buf->TryFlatten(StringShape(buf));
if (ok->IsFailure()) return ok;
- // Under certain circumstances (TryFlatten fails in String::Slice)
- // we can have a cons string under a slice. In this case we need
- // to get the flat string out of the cons!
+ // Under certain circumstances (TryFlattenIfNotFlat fails in
+ // String::Slice) we can have a cons string under a slice.
+ // In this case we need to get the flat string out of the cons!
if (StringShape(String::cast(ok)).IsCons()) {
ss->set_buffer(ConsString::cast(ok)->first());
}
@@ -2413,8 +2413,8 @@
return Heap::undefined_value();
}
- // TryFlatten before operating on the string.
- name->TryFlatten(StringShape(name));
+ // Try to flatten before operating on the string.
+ name->TryFlattenIfNotFlat(StringShape(name));
// Make sure name is not an index.
uint32_t index;
@@ -3065,9 +3065,7 @@
// 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.
- if (!IsFlat(shape)) {
- TryFlatten(shape); // shape is now no longer valid.
- }
+ TryFlattenIfNotFlat(shape); // shape is now no longer valid.
Access<StringInputBuffer> buffer(&string_input_buffer);
buffer->Reset(0, this);
int result = 0;
Modified: branches/bleeding_edge/src/objects.h
==============================================================================
--- branches/bleeding_edge/src/objects.h (original)
+++ branches/bleeding_edge/src/objects.h Mon Jan 26 00:35:41 2009
@@ -3131,15 +3131,17 @@
// to this method are not efficient unless the string is flat.
inline uint16_t Get(StringShape shape, int index);
- // Flatten the top level ConsString that is hiding behind this
+ // Try to flatten the top level ConsString that is hiding behind this
// string. This is a no-op unless the string is a ConsString or a
// SlicedString. Flatten mutates the ConsString and might return a
// failure.
- Object* Flatten(StringShape shape);
- // Try to flatten the string. Do not allow handling of allocation
- // failures. After calling TryFlatten, the string could still be a
- // ConsString.
- inline void TryFlatten(StringShape shape);
+ Object* TryFlatten(StringShape shape);
+
+ // Try to flatten the string. Checks first inline to see if it is
necessary.
+ // Do not handle allocation failures. After calling
TryFlattenIfNotFlat, 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(StringShape shape);
Vector<const char> ToAsciiVector();
Vector<const uc16> ToUC16Vector();
Modified: branches/bleeding_edge/src/parser.cc
==============================================================================
--- branches/bleeding_edge/src/parser.cc (original)
+++ branches/bleeding_edge/src/parser.cc Mon Jan 26 00:35:41 2009
@@ -1092,7 +1092,7 @@
Counters::total_parse_size.Increment(source->length(shape));
// Initialize parser state.
- source->TryFlatten(shape);
+ source->TryFlattenIfNotFlat(shape);
scanner_.Init(source, stream, 0);
ASSERT(target_stack_ == NULL);
@@ -1141,7 +1141,7 @@
bool is_expression) {
ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
StatsRateScope timer(&Counters::parse_lazy);
- source->TryFlatten(StringShape(*source));
+ source->TryFlattenIfNotFlat(StringShape(*source));
StringShape shape(*source);
Counters::total_parse_size.Increment(source->length(shape));
SafeStringInputBuffer buffer(source.location());
Modified: branches/bleeding_edge/src/runtime.cc
==============================================================================
--- branches/bleeding_edge/src/runtime.cc (original)
+++ branches/bleeding_edge/src/runtime.cc Mon Jan 26 00:35:41 2009
@@ -1060,7 +1060,7 @@
// Flatten the string. If someone wants to get a char at an index
// in a cons string, it is likely that more indices will be
// accessed.
- subject->TryFlatten(StringShape(subject));
+ subject->TryFlattenIfNotFlat(StringShape(subject));
StringShape shape(subject);
if (i >= static_cast<uint32_t>(subject->length(shape))) {
return Heap::nan_value();
@@ -1531,8 +1531,8 @@
CONVERT_CHECKED(String, pat, args[1]);
Object* index = args[2];
- sub->TryFlatten(StringShape(sub));
- pat->TryFlatten(StringShape(pat));
+ sub->TryFlattenIfNotFlat(StringShape(sub));
+ pat->TryFlattenIfNotFlat(StringShape(pat));
StringShape sub_shape(sub);
StringShape pat_shape(pat);
@@ -1591,8 +1591,8 @@
int d = str1->Get(shape1, 0) - str2->Get(shape2, 0);
if (d != 0) return Smi::FromInt(d);
- str1->TryFlatten(shape1); // Shapes are no longer valid now!
- str2->TryFlatten(shape2);
+ str1->TryFlattenIfNotFlat(shape1); // Shapes are no longer valid now!
+ str2->TryFlattenIfNotFlat(shape2);
static StringInputBuffer buf1;
static StringInputBuffer buf2;
@@ -1729,7 +1729,7 @@
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
StringShape shape(*string);
if (index < static_cast<uint32_t>(string->length(shape))) {
- string->TryFlatten(shape); // Invalidates shape!
+ string->TryFlattenIfNotFlat(shape); // Invalidates shape!
return LookupSingleCharacterStringFromCode(
string->Get(StringShape(*string), index));
}
@@ -1922,7 +1922,7 @@
result = SetElement(js_object, index, value);
} else {
Handle<String> key_string = Handle<String>::cast(key);
- key_string->TryFlatten(StringShape(*key_string));
+ key_string->TryFlattenIfNotFlat(StringShape(*key_string));
result = SetProperty(js_object, key_string, value, attr);
}
if (result.is_null()) return Failure::Exception();
@@ -2194,7 +2194,7 @@
NoHandleAllocation ha;
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, subject, args[0]);
- subject->TryFlatten(StringShape(subject));
+ subject->TryFlattenIfNotFlat(StringShape(subject));
return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX));
}
@@ -2277,7 +2277,7 @@
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
- source->TryFlatten(StringShape(source));
+ source->TryFlattenIfNotFlat(StringShape(source));
int escaped_length = 0;
int length = source->length();
@@ -2391,7 +2391,7 @@
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
- source->TryFlatten(StringShape(source));
+ source->TryFlattenIfNotFlat(StringShape(source));
StringShape source_shape(source);
bool ascii = true;
@@ -2440,7 +2440,7 @@
CONVERT_DOUBLE_CHECKED(n, args[1]);
int radix = FastD2I(n);
- s->TryFlatten(StringShape(s));
+ s->TryFlattenIfNotFlat(StringShape(s));
StringShape shape(s);
@@ -2513,7 +2513,7 @@
NoHandleAllocation ha;
CONVERT_CHECKED(String, s, args[0]);
- s->TryFlatten(StringShape(s));
+ s->TryFlattenIfNotFlat(StringShape(s));
StringShape shape(s);
int raw_string_length = s->length(shape);
@@ -3117,8 +3117,8 @@
if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER);
- x->TryFlatten(x_shape); // Shapes are no longer valid!
- y->TryFlatten(y_shape);
+ x->TryFlattenIfNotFlat(x_shape); // Shapes are no longer valid!
+ y->TryFlattenIfNotFlat(y_shape);
static StringInputBuffer bufx;
static StringInputBuffer bufy;
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---