- Inlined the code for make simple cons strings.
- Simplify generated code for Runtime_** functions. Review URL: http://codereview.chromium.org/149068 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2283 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
0746d93014
commit
252514ca23
@ -92,8 +92,6 @@ Handle<String> Factory::NewRawTwoByteString(int length,
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
22
src/heap.cc
22
src/heap.cc
@ -1536,14 +1536,24 @@ Object* Heap::AllocateSharedFunctionInfo(Object* name) {
|
||||
}
|
||||
|
||||
|
||||
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 @@ Object* Heap::AllocateConsString(String* first,
|
||||
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);
|
||||
|
@ -507,8 +507,7 @@ class Heap : public AllStatic {
|
||||
// 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
|
||||
|
@ -50,9 +50,8 @@ namespace v8 {
|
||||
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 @@ namespace internal {
|
||||
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_NumberMod(Arguments args) {
|
||||
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 @@ static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) {
|
||||
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);
|
||||
|
@ -611,6 +611,11 @@ Failure* Top::ReThrow(Object* exception, MessageLocation* location) {
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
|
@ -239,6 +239,7 @@ class Top {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user