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

Side by Side Diff: src/runtime.cc

Issue 991002: Add heuristic for flattening strings before comparing them. (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « src/heap-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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 5055 matching lines...) Expand 10 before | Expand all | Expand 10 after
5066 prefix_length = y->length(); 5066 prefix_length = y->length();
5067 equal_prefix_result = Smi::FromInt(GREATER); 5067 equal_prefix_result = Smi::FromInt(GREATER);
5068 } else if (y->length() > prefix_length) { 5068 } else if (y->length() > prefix_length) {
5069 equal_prefix_result = Smi::FromInt(LESS); 5069 equal_prefix_result = Smi::FromInt(LESS);
5070 } 5070 }
5071 int r; 5071 int r;
5072 if (x->IsAsciiRepresentation()) { 5072 if (x->IsAsciiRepresentation()) {
5073 Vector<const char> x_chars = x->ToAsciiVector(); 5073 Vector<const char> x_chars = x->ToAsciiVector();
5074 if (y->IsAsciiRepresentation()) { 5074 if (y->IsAsciiRepresentation()) {
5075 Vector<const char> y_chars = y->ToAsciiVector(); 5075 Vector<const char> y_chars = y->ToAsciiVector();
5076 r = memcmp(x_chars.start(), y_chars.start(), prefix_length); 5076 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
5077 } else { 5077 } else {
5078 Vector<const uc16> y_chars = y->ToUC16Vector(); 5078 Vector<const uc16> y_chars = y->ToUC16Vector();
5079 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); 5079 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
5080 } 5080 }
5081 } else { 5081 } else {
5082 Vector<const uc16> x_chars = x->ToUC16Vector(); 5082 Vector<const uc16> x_chars = x->ToUC16Vector();
5083 if (y->IsAsciiRepresentation()) { 5083 if (y->IsAsciiRepresentation()) {
5084 Vector<const char> y_chars = y->ToAsciiVector(); 5084 Vector<const char> y_chars = y->ToAsciiVector();
5085 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); 5085 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
5086 } else { 5086 } else {
(...skipping 27 matching lines...) Expand all
5114 if (x->length() == 0) return Smi::FromInt(EQUAL); 5114 if (x->length() == 0) return Smi::FromInt(EQUAL);
5115 return Smi::FromInt(GREATER); 5115 return Smi::FromInt(GREATER);
5116 } else if (x->length() == 0) { 5116 } else if (x->length() == 0) {
5117 return Smi::FromInt(LESS); 5117 return Smi::FromInt(LESS);
5118 } 5118 }
5119 5119
5120 int d = x->Get(0) - y->Get(0); 5120 int d = x->Get(0) - y->Get(0);
5121 if (d < 0) return Smi::FromInt(LESS); 5121 if (d < 0) return Smi::FromInt(LESS);
5122 else if (d > 0) return Smi::FromInt(GREATER); 5122 else if (d > 0) return Smi::FromInt(GREATER);
5123 5123
5124 x->TryFlatten(); 5124 Object* obj = Heap::PrepareForCompare(x);
5125 y->TryFlatten(); 5125 if (obj->IsFailure()) return obj;
5126 obj = Heap::PrepareForCompare(y);
5127 if (obj->IsFailure()) return obj;
5126 5128
5127 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) 5129 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
5128 : StringInputBufferCompare(x, y); 5130 : StringInputBufferCompare(x, y);
5129 } 5131 }
5130 5132
5131 5133
5132 static Object* Runtime_Math_acos(Arguments args) { 5134 static Object* Runtime_Math_acos(Arguments args) {
5133 NoHandleAllocation ha; 5135 NoHandleAllocation ha;
5134 ASSERT(args.length() == 1); 5136 ASSERT(args.length() == 1);
5135 Counters::math_acos.Increment(); 5137 Counters::math_acos.Increment();
(...skipping 4205 matching lines...) Expand 10 before | Expand all | Expand 10 after
9341 } else { 9343 } else {
9342 // Handle last resort GC and make sure to allow future allocations 9344 // Handle last resort GC and make sure to allow future allocations
9343 // to grow the heap without causing GCs (if possible). 9345 // to grow the heap without causing GCs (if possible).
9344 Counters::gc_last_resort_from_js.Increment(); 9346 Counters::gc_last_resort_from_js.Increment();
9345 Heap::CollectAllGarbage(false); 9347 Heap::CollectAllGarbage(false);
9346 } 9348 }
9347 } 9349 }
9348 9350
9349 9351
9350 } } // namespace v8::internal 9352 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698