Author: [email protected]
Date: Fri Jun 26 06:09:50 2009
New Revision: 2283

Modified:
    branches/bleeding_edge/src/factory.cc
    branches/bleeding_edge/src/heap.cc
    branches/bleeding_edge/src/heap.h
    branches/bleeding_edge/src/runtime.cc
    branches/bleeding_edge/src/top.cc
    branches/bleeding_edge/src/top.h

Log:
- Inlined the code for make simple cons strings.
- Simplify generated code for Runtime_** functions.

Review URL: http://codereview.chromium.org/149068

Modified: branches/bleeding_edge/src/factory.cc
==============================================================================
--- branches/bleeding_edge/src/factory.cc       (original)
+++ branches/bleeding_edge/src/factory.cc       Fri Jun 26 06:09:50 2009
@@ -92,8 +92,6 @@

  Handle<String> Factory::NewConsString(Handle<String> first,
                                        Handle<String> second) {
-  if (first->length() == 0) return second;
-  if (second->length() == 0) return first;
    CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String);
  }


Modified: branches/bleeding_edge/src/heap.cc
==============================================================================
--- branches/bleeding_edge/src/heap.cc  (original)
+++ branches/bleeding_edge/src/heap.cc  Fri Jun 26 06:09:50 2009
@@ -1536,14 +1536,24 @@
  }


-Object* Heap::AllocateConsString(String* first,
-                                 String* second) {
+Object* Heap::AllocateConsString(String* first, String* second) {
    int first_length = first->length();
+  if (first_length == 0) return second;
+
    int second_length = second->length();
+  if (second_length == 0) return first;
+
    int length = first_length + second_length;
    bool is_ascii = first->IsAsciiRepresentation()
        && second->IsAsciiRepresentation();

+  // Make sure that an out of memory exception is thrown if the length
+  // of the new cons string is too large to fit in a Smi.
+  if (length > Smi::kMaxValue || length < -0) {
+    Top::context()->mark_out_of_memory();
+    return Failure::OutOfMemoryException();
+  }
+
    // If the resulting string is small make a flat string.
    if (length < String::kMinNonFlatLength) {
      ASSERT(first->IsFlat());
@@ -1553,8 +1563,12 @@
        if (result->IsFailure()) return result;
        // Copy the characters into the new object.
        char* dest = SeqAsciiString::cast(result)->GetChars();
-      String::WriteToFlat(first, dest, 0, first_length);
-      String::WriteToFlat(second, dest + first_length, 0, second_length);
+      // Copy first part.
+      char* src = SeqAsciiString::cast(first)->GetChars();
+      for (int i = 0; i < first_length; i++) *dest++ = src[i];
+      // Copy second part.
+      src = SeqAsciiString::cast(second)->GetChars();
+      for (int i = 0; i < second_length; i++) *dest++ = src[i];
        return result;
      } else {
        Object* result = AllocateRawTwoByteString(length);

Modified: branches/bleeding_edge/src/heap.h
==============================================================================
--- branches/bleeding_edge/src/heap.h   (original)
+++ branches/bleeding_edge/src/heap.h   Fri Jun 26 06:09:50 2009
@@ -507,8 +507,7 @@
    // Returns Failure::RetryAfterGC(requested_bytes, space) if the  
allocation
    // failed.
    // Please note this does not perform a garbage collection.
-  static Object* AllocateConsString(String* first,
-                                    String* second);
+  static Object* AllocateConsString(String* first, 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

Modified: branches/bleeding_edge/src/runtime.cc
==============================================================================
--- branches/bleeding_edge/src/runtime.cc       (original)
+++ branches/bleeding_edge/src/runtime.cc       Fri Jun 26 06:09:50 2009
@@ -50,9 +50,8 @@
  namespace internal {


-#define RUNTIME_ASSERT(value) do {                                   \
-  if (!(value)) return IllegalOperation();                           \
-} while (false)
+#define RUNTIME_ASSERT(value) \
+  if (!(value)) return Top::ThrowIllegalOperation();

  // Cast the given object to a value of the specified type and store
  // it in a variable with the given name.  If the object is not of the
@@ -97,11 +96,6 @@
  static StaticResource<StringInputBuffer> runtime_string_input_buffer;


-static Object* IllegalOperation() {
-  return Top::Throw(Heap::illegal_access_symbol());
-}
-
-
  static Object* DeepCopyBoilerplate(JSObject* boilerplate) {
    StackLimitCheck check;
    if (check.HasOverflowed()) return Top::StackOverflow();
@@ -3704,20 +3698,8 @@
  static Object* Runtime_StringAdd(Arguments args) {
    NoHandleAllocation ha;
    ASSERT(args.length() == 2);
-
    CONVERT_CHECKED(String, str1, args[0]);
    CONVERT_CHECKED(String, str2, args[1]);
-  int len1 = str1->length();
-  int len2 = str2->length();
-  if (len1 == 0) return str2;
-  if (len2 == 0) return str1;
-  int length_sum = len1 + len2;
-  // Make sure that an out of memory exception is thrown if the length
-  // of the new cons string is too large to fit in a Smi.
-  if (length_sum > Smi::kMaxValue || length_sum < 0) {
-    Top::context()->mark_out_of_memory();
-    return Failure::OutOfMemoryException();
-  }
    return Heap::AllocateConsString(str1, str2);
  }

@@ -4584,7 +4566,7 @@
    ASSERT(args.length() == 2);

    if (!args[0]->IsContext() || !args[1]->IsString()) {
-    return MakePair(IllegalOperation(), NULL);
+    return MakePair(Top::ThrowIllegalOperation(), NULL);
    }
    Handle<Context> context = args.at<Context>(0);
    Handle<String> name = args.at<String>(1);

Modified: branches/bleeding_edge/src/top.cc
==============================================================================
--- branches/bleeding_edge/src/top.cc   (original)
+++ branches/bleeding_edge/src/top.cc   Fri Jun 26 06:09:50 2009
@@ -611,6 +611,11 @@
  }


+Failure* Top::ThrowIllegalOperation() {
+  return Throw(Heap::illegal_access_symbol());
+}
+
+
  void Top::ScheduleThrow(Object* exception) {
    // When scheduling a throw we first throw the exception to get the
    // error reporting if it is uncaught before rescheduling it.

Modified: branches/bleeding_edge/src/top.h
==============================================================================
--- branches/bleeding_edge/src/top.h    (original)
+++ branches/bleeding_edge/src/top.h    Fri Jun 26 06:09:50 2009
@@ -239,6 +239,7 @@
    static Failure* ReThrow(Object* exception, MessageLocation* location =  
NULL);
    static void ScheduleThrow(Object* exception);
    static void ReportPendingMessages();
+  static Failure* ThrowIllegalOperation();

    // Promote a scheduled exception to pending. Asserts  
has_scheduled_exception.
    static Object* PromoteScheduledException();

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

Reply via email to