Author: [EMAIL PROTECTED]
Date: Wed Nov  5 03:53:10 2008
New Revision: 696

Modified:
    trunk/src/api.cc
    trunk/src/compiler.cc
    trunk/src/conversions.cc
    trunk/src/factory.cc
    trunk/src/factory.h
    trunk/src/handles.cc
    trunk/src/heap.cc
    trunk/src/heap.h
    trunk/src/jsregexp.cc
    trunk/src/log.cc
    trunk/src/objects.cc
    trunk/src/objects.h
    trunk/src/parser.cc
    trunk/src/runtime.cc
    trunk/test/cctest/test-strings.cc

Log:
Push string shape fixes to trunk (version 0.4.3.1).
Review URL: http://codereview.chromium.org/9181

Modified: trunk/src/api.cc
==============================================================================
--- trunk/src/api.cc    (original)
+++ trunk/src/api.cc    Wed Nov  5 03:53:10 2008
@@ -2202,7 +2202,7 @@


  const char* v8::V8::GetVersion() {
-  return "0.4.3";
+  return "0.4.3.1";
  }



Modified: trunk/src/compiler.cc
==============================================================================
--- trunk/src/compiler.cc       (original)
+++ trunk/src/compiler.cc       Wed Nov  5 03:53:10 2008
@@ -209,8 +209,7 @@
  Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
                                           int line_offset,
                                           bool is_global) {
-  StringShape source_shape(*source);
-  int source_length = source->length(source_shape);
+  int source_length = source->length();
    Counters::total_eval_size.Increment(source_length);
    Counters::total_compile_size.Increment(source_length);


Modified: trunk/src/conversions.cc
==============================================================================
--- trunk/src/conversions.cc    (original)
+++ trunk/src/conversions.cc    Wed Nov  5 03:53:10 2008
@@ -121,15 +121,14 @@


  static inline bool SubStringEquals(String* str, int index, const char*  
other) {
-  StringShape shape(str);
    HandleScope scope;
-  int str_length = str->length(shape);
+  int str_length = str->length();
    int other_length = strlen(other);
    int end = index + other_length < str_length ?
              index + other_length :
              str_length;
    Handle<String> slice =
-      Factory::NewStringSlice(Handle<String>(str), shape, index, end);
+      Factory::NewStringSlice(Handle<String>(str), index, end);
    return slice->IsEqualTo(Vector<const char>(other, other_length));
  }


Modified: trunk/src/factory.cc
==============================================================================
--- trunk/src/factory.cc        (original)
+++ trunk/src/factory.cc        Wed Nov  5 03:53:10 2008
@@ -95,19 +95,14 @@
                                        StringShape second_shape) {
    if (first->length(first_shape) == 0) return second;
    if (second->length(second_shape) == 0) return first;
-  CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first,
-                                              first_shape,
-                                              *second,
-                                              second_shape),
-                     String);
+  CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String);
  }


  Handle<String> Factory::NewStringSlice(Handle<String> str,
-                                       StringShape shape,
                                         int begin,
                                         int end) {
-  CALL_HEAP_FUNCTION(str->Slice(shape, begin, end), String);
+  CALL_HEAP_FUNCTION(str->Slice(begin, end), String);
  }



Modified: trunk/src/factory.h
==============================================================================
--- trunk/src/factory.h (original)
+++ trunk/src/factory.h Wed Nov  5 03:53:10 2008
@@ -105,7 +105,6 @@
    // Create a new sliced string object which represents a substring of a
    // backing string.
    static Handle<String> NewStringSlice(Handle<String> str,
-                                       StringShape shape,
                                         int begin,
                                         int end);


Modified: trunk/src/handles.cc
==============================================================================
--- trunk/src/handles.cc        (original)
+++ trunk/src/handles.cc        Wed Nov  5 03:53:10 2008
@@ -217,7 +217,7 @@


  Handle<String> SubString(Handle<String> str, int start, int end) {
-  CALL_HEAP_FUNCTION(str->Slice(StringShape(*str), start, end), String);
+  CALL_HEAP_FUNCTION(str->Slice(start, end), String);
  }



Modified: trunk/src/heap.cc
==============================================================================
--- trunk/src/heap.cc   (original)
+++ trunk/src/heap.cc   Wed Nov  5 03:53:10 2008
@@ -783,8 +783,7 @@
    // is a candidate for being shortcut by the scavenger.
    ASSERT(object->map() == map);
    if (map->instance_type() >= FIRST_NONSTRING_TYPE) return false;
-  StringShape shape(map);
-  return (shape.representation_tag() == kConsStringTag) &&
+  return (StringShape(map).representation_tag() == kConsStringTag) &&
           (ConsString::cast(object)->unchecked_second() ==  
Heap::empty_string());
  }

@@ -1347,9 +1346,9 @@


  Object* Heap::AllocateConsString(String* first,
-                                 StringShape first_shape,
-                                 String* second,
-                                 StringShape second_shape) {
+                                 String* second) {
+  StringShape first_shape(first);
+  StringShape second_shape(second);
    int first_length = first->length(first_shape);
    int second_length = second->length(second_shape);
    int length = first_length + second_length;
@@ -1411,9 +1410,9 @@


  Object* Heap::AllocateSlicedString(String* buffer,
-                                   StringShape buffer_shape,
                                     int start,
                                     int end) {
+  StringShape buffer_shape(buffer);
    int length = end - start;

    // If the resulting string is small make a sub string.

Modified: trunk/src/heap.h
==============================================================================
--- trunk/src/heap.h    (original)
+++ trunk/src/heap.h    Wed Nov  5 03:53:10 2008
@@ -495,9 +495,7 @@
    // failed.
    // Please note this does not perform a garbage collection.
    static Object* AllocateConsString(String* first,
-                                    StringShape first_shape,
-                                    String* second,
-                                    StringShape second_shape);
+                                    String* second);

    // Allocates a new sliced string object which is a slice of an underlying
    // string buffer stretching from the index start (inclusive) to the index
@@ -506,7 +504,6 @@
    // failed.
    // Please note this does not perform a garbage collection.
    static Object* AllocateSlicedString(String* buffer,
-                                      StringShape buffer_shape,
                                        int start,
                                        int end);


Modified: trunk/src/jsregexp.cc
==============================================================================
--- trunk/src/jsregexp.cc       (original)
+++ trunk/src/jsregexp.cc       Wed Nov  5 03:53:10 2008
@@ -132,6 +132,7 @@
    StringShape shape(*pattern);
    if (!pattern->IsFlat(shape)) {
      FlattenString(pattern);
+    shape = StringShape(*pattern);
    }
    Handle<String> flat_string(shape.IsCons() ?
      String::cast(ConsString::cast(*pattern)->first()) :

Modified: trunk/src/log.cc
==============================================================================
--- trunk/src/log.cc    (original)
+++ trunk/src/log.cc    Wed Nov  5 03:53:10 2008
@@ -431,8 +431,7 @@
    LogRegExpSource(regexp);
    fprintf(logfile_, ",");
    LogString(input_string);
-  StringShape shape(*input_string);
-  fprintf(logfile_, ",%d..%d\n", start_index, input_string->length(shape));
+  fprintf(logfile_, ",%d..%d\n", start_index, input_string->length());
  #endif
  }


Modified: trunk/src/objects.cc
==============================================================================
--- trunk/src/objects.cc        (original)
+++ trunk/src/objects.cc        Wed Nov  5 03:53:10 2008
@@ -3717,21 +3717,6 @@
  }


-Object* SlicedString::SlicedStringFlatten() {
-  // The SlicedString constructor should ensure that there are no
-  // SlicedStrings that are constructed directly on top of other
-  // SlicedStrings.
-  String* buf = String::cast(buffer());
-  StringShape buf_shape(buf);
-  ASSERT(!buf_shape.IsSliced());
-  if (buf_shape.IsCons()) {
-    Object* ok = buf->Flatten(buf_shape);
-    if (ok->IsFailure()) return ok;
-  }
-  return this;
-}
-
-
  template <typename sinkchar>
  void String::WriteToFlat(String* src,
                           StringShape src_shape,
@@ -3975,8 +3960,7 @@


  bool String::MarkAsUndetectable() {
-  StringShape shape(this);
-  if (shape.IsSymbol()) return false;
+  if (StringShape(this).IsSymbol()) return false;

    Map* map = this->map();
    if (map == Heap::short_string_map()) {
@@ -4134,7 +4118,8 @@
  }


-Object* String::Slice(StringShape shape, int start, int end) {
+Object* String::Slice(int start, int end) {
+  StringShape shape(this);
    if (start == 0 && end == length(shape)) return this;
    if (shape.representation_tag() == kSlicedStringTag) {
      // Translate slices of a SlicedString into slices of the
@@ -4142,11 +4127,10 @@
      SlicedString* str = SlicedString::cast(this);
      String* buf = str->buffer();
      return Heap::AllocateSlicedString(buf,
-                                      StringShape(buf),
                                        str->start() + start,
                                        str->start() + end);
    }
-  Object* result = Heap::AllocateSlicedString(this, shape, start, end);
+  Object* result = Heap::AllocateSlicedString(this, start, end);
    if (result->IsFailure()) {
      return result;
    }

Modified: trunk/src/objects.h
==============================================================================
--- trunk/src/objects.h (original)
+++ trunk/src/objects.h Wed Nov  5 03:53:10 2008
@@ -3024,7 +3024,9 @@
  // the shape of the string is given its own class so that it can be  
retrieved
  // once and used for several string operations.  A StringShape is small  
enough
  // to be passed by value and is immutable, but be aware that flattening a
-// string can potentially alter its shape.
+// string can potentially alter its shape.  Also be aware that a GC caused  
by
+// something else can alter the shape of a string due to ConsString
+// shortcutting.
  //
  // Most of the methods designed to interrogate a string as to its exact  
nature
  // have been made into methods on StringShape in order to encourage the  
use of
@@ -3116,7 +3118,7 @@
    bool MarkAsUndetectable();

    // Slice the string and return a substring.
-  Object* Slice(StringShape shape, int from, int to);
+  Object* Slice(int from, int to);

    // String equality operations.
    inline bool Equals(String* other);
@@ -3470,9 +3472,6 @@

    // Dispatched behavior.
    uint16_t SlicedStringGet(int index);
-
-  // Flatten any ConsString hiding behind this SlicedString.
-  Object* SlicedStringFlatten();

    // Casting.
    static inline SlicedString* cast(Object* obj);

Modified: trunk/src/parser.cc
==============================================================================
--- trunk/src/parser.cc (original)
+++ trunk/src/parser.cc Wed Nov  5 03:53:10 2008
@@ -790,8 +790,8 @@
                                     bool is_expression) {
    ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
    StatsRateScope timer(&Counters::parse_lazy);
+  source->TryFlatten(StringShape(*source));
    StringShape shape(*source);
-  source->TryFlatten(shape);
    Counters::total_parse_size.Increment(source->length(shape));
    SafeStringInputBuffer buffer(source.location());


Modified: trunk/src/runtime.cc
==============================================================================
--- trunk/src/runtime.cc        (original)
+++ trunk/src/runtime.cc        Wed Nov  5 03:53:10 2008
@@ -969,12 +969,12 @@
    // 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));
    StringShape shape(subject);
-  subject->TryFlatten(shape);  // shape no longer valid!
-  if (i >= static_cast<uint32_t>(subject->length(StringShape(subject)))) {
+  if (i >= static_cast<uint32_t>(subject->length(shape))) {
      return Heap::nan_value();
    }
-  return Smi::FromInt(subject->Get(StringShape(subject), i));
+  return Smi::FromInt(subject->Get(shape, i));
  }


@@ -1355,10 +1355,9 @@
                           int start_index) {
    ASSERT(0 <= start_index);
    StringShape sub_shape(*sub);
-  StringShape pat_shape(*pat);
    ASSERT(start_index <= sub->length(sub_shape));

-  int pattern_length = pat->length(pat_shape);
+  int pattern_length = pat->length();
    if (pattern_length == 0) return start_index;

    int subject_length = sub->length(sub_shape);
@@ -1368,6 +1367,7 @@
      FlattenString(sub);
      sub_shape = StringShape(*sub);
    }
+  StringShape pat_shape(*pat);
    // Searching for one specific character is common.  For one
    // character patterns linear search is necessary, so any smart
    // algorithm is unnecessary overhead.
@@ -1386,6 +1386,7 @@
    if (!pat->IsFlat(pat_shape)) {
      FlattenString(pat);
      pat_shape = StringShape(*pat);
+    sub_shape = StringShape(*sub);
    }

    AssertNoAllocation no_heap_allocation;  // ensure vectors stay valid
@@ -1520,12 +1521,10 @@
    int start = FastD2I(from_number);
    int end = FastD2I(to_number);

-  StringShape shape(value);
-
    RUNTIME_ASSERT(end >= start);
    RUNTIME_ASSERT(start >= 0);
-  RUNTIME_ASSERT(end <= value->length(shape));
-  return value->Slice(shape, start, end);
+  RUNTIME_ASSERT(end <= value->length());
+  return value->Slice(start, end);
  }


@@ -1908,8 +1907,7 @@
      uint32_t index;
      if (key->AsArrayIndex(&index)) {
        String* string = String::cast(args[0]);
-      StringShape shape(string);
-      if (index < static_cast<uint32_t>(string->length(shape)))
+      if (index < static_cast<uint32_t>(string->length()))
          return Heap::true_value();
      }
    }
@@ -2682,10 +2680,8 @@

    CONVERT_CHECKED(String, str1, args[0]);
    CONVERT_CHECKED(String, str2, args[1]);
-  StringShape shape1(str1);
-  StringShape shape2(str2);
-  int len1 = str1->length(shape1);
-  int len2 = str2->length(shape2);
+  int len1 = str1->length();
+  int len2 = str2->length();
    if (len1 == 0) return str2;
    if (len2 == 0) return str1;
    int length_sum = len1 + len2;
@@ -2695,7 +2691,7 @@
      Top::context()->mark_out_of_memory();
      return Failure::OutOfMemoryException();
    }
-  return Heap::AllocateConsString(str1, shape1, str2, shape2);
+  return Heap::AllocateConsString(str1, str2);
  }



Modified: trunk/test/cctest/test-strings.cc
==============================================================================
--- trunk/test/cctest/test-strings.cc   (original)
+++ trunk/test/cctest/test-strings.cc   Wed Nov  5 03:53:10 2008
@@ -215,10 +215,8 @@
      CHECK_EQ(c, buffer2.GetNext());
      i++;
    }
-  StringShape shape1(*s1);
-  StringShape shape2(*s2);
-  s1->Get(shape1, s1->length(shape1) - 1);
-  s2->Get(shape2, s2->length(shape2) - 1);
+  s1->Get(StringShape(*s1), s1->length() - 1);
+  s2->Get(StringShape(*s2), s2->length() - 1);
  }


@@ -251,12 +249,10 @@
    printf("7\n");
    Handle<String> right_deep_slice =
        Factory::NewStringSlice(left_deep_asymmetric,
-                              StringShape(*left_deep_asymmetric),
                                left_deep_asymmetric->length() - 1050,
                                left_deep_asymmetric->length() - 50);
    Handle<String> left_deep_slice =
        Factory::NewStringSlice(right_deep_asymmetric,
-                              StringShape(*right_deep_asymmetric),
                                right_deep_asymmetric->length() - 1050,
                                right_deep_asymmetric->length() - 50);
    printf("8\n");
@@ -283,7 +279,6 @@
    int start = gen() % underlying->length();
    int end = start + gen() % (underlying->length() - start);
    return Factory::NewStringSlice(underlying,
-                                 StringShape(*underlying),
                                   start,
                                   end);
  }

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to