Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: src/runtime.cc

Issue 6991007: Don't flatten every time we call CharCodeAt Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handle flat cons string. Flatten entire string. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/objects-inl.h ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 if (index->IsSmi()) { 2053 if (index->IsSmi()) {
2054 int value = Smi::cast(index)->value(); 2054 int value = Smi::cast(index)->value();
2055 if (value < 0) return isolate->heap()->nan_value(); 2055 if (value < 0) return isolate->heap()->nan_value();
2056 i = value; 2056 i = value;
2057 } else { 2057 } else {
2058 ASSERT(index->IsHeapNumber()); 2058 ASSERT(index->IsHeapNumber());
2059 double value = HeapNumber::cast(index)->value(); 2059 double value = HeapNumber::cast(index)->value();
2060 i = static_cast<uint32_t>(DoubleToInteger(value)); 2060 i = static_cast<uint32_t>(DoubleToInteger(value));
2061 } 2061 }
2062 2062
2063 // Flatten the string. If someone wants to get a char at an index
2064 // in a cons string, it is likely that more indices will be
2065 // accessed.
2066 Object* flat;
2067 { MaybeObject* maybe_flat = subject->TryFlatten();
2068 if (!maybe_flat->ToObject(&flat)) return maybe_flat;
2069 }
2070 subject = String::cast(flat);
2071
2072 if (i >= static_cast<uint32_t>(subject->length())) { 2063 if (i >= static_cast<uint32_t>(subject->length())) {
2073 return isolate->heap()->nan_value(); 2064 return isolate->heap()->nan_value();
2074 } 2065 }
2075 2066
2076 return Smi::FromInt(subject->Get(i)); 2067 return subject->GetMayFlatten(i);
2077 } 2068 }
2078 2069
2079 2070
2080 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) { 2071 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) {
2081 NoHandleAllocation ha; 2072 NoHandleAllocation ha;
2082 ASSERT(args.length() == 1); 2073 ASSERT(args.length() == 1);
2083 return CharFromCode(isolate, args[0]); 2074 return CharFromCode(isolate, args[0]);
2084 } 2075 }
2085 2076
2086 2077
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after
3629 isolate->heap()->AllocateStringFromAscii(CStrVector(str)); 3620 isolate->heap()->AllocateStringFromAscii(CStrVector(str));
3630 DeleteArray(str); 3621 DeleteArray(str);
3631 return res; 3622 return res;
3632 } 3623 }
3633 3624
3634 3625
3635 // Returns a single character string where first character equals 3626 // Returns a single character string where first character equals
3636 // string->Get(index). 3627 // string->Get(index).
3637 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { 3628 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
3638 if (index < static_cast<uint32_t>(string->length())) { 3629 if (index < static_cast<uint32_t>(string->length())) {
3639 string->TryFlatten();
3640 return LookupSingleCharacterStringFromCode( 3630 return LookupSingleCharacterStringFromCode(
3641 string->Get(index)); 3631 StringGetMayFlatten(string, index));
3642 } 3632 }
3643 return Execution::CharAt(string, index); 3633 return Execution::CharAt(string, index);
3644 } 3634 }
3645 3635
3646 3636
3647 MaybeObject* Runtime::GetElementOrCharAt(Isolate* isolate, 3637 MaybeObject* Runtime::GetElementOrCharAt(Isolate* isolate,
3648 Handle<Object> object, 3638 Handle<Object> object,
3649 uint32_t index) { 3639 uint32_t index) {
3650 // Handle [] indexing on Strings 3640 // Handle [] indexing on Strings
3651 if (object->IsString()) { 3641 if (object->IsString()) {
(...skipping 8522 matching lines...) Expand 10 before | Expand all | Expand 10 after
12174 } else { 12164 } else {
12175 // Handle last resort GC and make sure to allow future allocations 12165 // Handle last resort GC and make sure to allow future allocations
12176 // to grow the heap without causing GCs (if possible). 12166 // to grow the heap without causing GCs (if possible).
12177 isolate->counters()->gc_last_resort_from_js()->Increment(); 12167 isolate->counters()->gc_last_resort_from_js()->Increment();
12178 isolate->heap()->CollectAllGarbage(false); 12168 isolate->heap()->CollectAllGarbage(false);
12179 } 12169 }
12180 } 12170 }
12181 12171
12182 12172
12183 } } // namespace v8::internal 12173 } } // namespace v8::internal
OLDNEW
« src/objects-inl.h ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698