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

Side by Side Diff: src/objects.cc

Issue 6991007: Don't flatten every time we call CharCodeAt Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | 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 5163 matching lines...) Expand 10 before | Expand all | Expand 10 after
5174 } 5174 }
5175 } 5175 }
5176 5176
5177 5177
5178 uint16_t ConsString::ConsStringGet(int index) { 5178 uint16_t ConsString::ConsStringGet(int index) {
5179 ASSERT(index >= 0 && index < this->length()); 5179 ASSERT(index >= 0 && index < this->length());
5180 5180
5181 // Check for a flattened cons string 5181 // Check for a flattened cons string
5182 if (second()->length() == 0) { 5182 if (second()->length() == 0) {
5183 String* left = first(); 5183 String* left = first();
5184 return left->Get(index); 5184 return FlatString::cast(left)->FlatStringGet(index);
5185 } 5185 }
5186 5186
5187 String* string = String::cast(this); 5187 String* string = String::cast(this);
5188 5188
5189 while (true) { 5189 while (true) {
5190 if (StringShape(string).IsCons()) { 5190 if (StringShape(string).IsCons()) {
5191 ConsString* cons_string = ConsString::cast(string); 5191 ConsString* cons_string = ConsString::cast(string);
5192 String* left = cons_string->first(); 5192 String* left = cons_string->first();
5193 if (left->length() > index) { 5193 if (left->length() > index) {
5194 string = left; 5194 string = left;
5195 } else { 5195 } else {
5196 index -= left->length(); 5196 index -= left->length();
5197 string = cons_string->second(); 5197 string = cons_string->second();
5198 } 5198 }
5199 } else { 5199 } else {
5200 return string->Get(index); 5200 return FlatString::cast(string)->FlatStringGet(index);
5201 } 5201 }
5202 } 5202 }
5203 5203
5204 UNREACHABLE(); 5204 UNREACHABLE();
5205 return 0; 5205 return 0;
5206 } 5206 }
5207 5207
5208 5208
5209 MaybeObject* ConsString::ConsStringGetMayFlatten(int index) {
5210 ASSERT(index >= 0);
5211 ASSERT(index < this->length());
5212
5213 String* string = this;
5214 if (this->GetIsolate()->ShouldFlattenString()) {
Vitaly Repeshko 2011/05/10 13:07:02 Here "this" can already be a flat cons (i.e. with
Lasse Reichstein 2011/05/10 16:27:46 Good point. We should probably not get here for a
5215 MaybeObject* flatten_result = this->TryFlatten();
5216 if (flatten_result->IsFailure()) return flatten_result;
5217 string = String::cast(flatten_result->ToObjectUnchecked());
5218 }
5219 return Smi::FromInt(string->Get(index));
5220 }
5221
5222
5209 template <typename sinkchar> 5223 template <typename sinkchar>
5210 void String::WriteToFlat(String* src, 5224 void String::WriteToFlat(String* src,
5211 sinkchar* sink, 5225 sinkchar* sink,
5212 int f, 5226 int f,
5213 int t) { 5227 int t) {
5214 String* source = src; 5228 String* source = src;
5215 int from = f; 5229 int from = f;
5216 int to = t; 5230 int to = t;
5217 while (true) { 5231 while (true) {
5218 ASSERT(0 <= from && from <= to && to <= source->length()); 5232 ASSERT(0 <= from && from <= to && to <= source->length());
(...skipping 5202 matching lines...) Expand 10 before | Expand all | Expand 10 after
10421 if (break_point_objects()->IsUndefined()) return 0; 10435 if (break_point_objects()->IsUndefined()) return 0;
10422 // Single beak point. 10436 // Single beak point.
10423 if (!break_point_objects()->IsFixedArray()) return 1; 10437 if (!break_point_objects()->IsFixedArray()) return 1;
10424 // Multiple break points. 10438 // Multiple break points.
10425 return FixedArray::cast(break_point_objects())->length(); 10439 return FixedArray::cast(break_point_objects())->length();
10426 } 10440 }
10427 #endif 10441 #endif
10428 10442
10429 10443
10430 } } // namespace v8::internal 10444 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698