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

Side by Side Diff: src/handles.cc

Issue 608012: Use binary search in GetScriptLineNumber. (Closed)
Patch Set: Created 10 years, 10 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 | « no previous file | test/cctest/test-compiler.cc » ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 script->set_line_ends(*array); 477 script->set_line_ends(*array);
478 ASSERT(script->line_ends()->IsFixedArray()); 478 ASSERT(script->line_ends()->IsFixedArray());
479 } 479 }
480 480
481 481
482 // Convert code position into line number. 482 // Convert code position into line number.
483 int GetScriptLineNumber(Handle<Script> script, int code_pos) { 483 int GetScriptLineNumber(Handle<Script> script, int code_pos) {
484 InitScriptLineEnds(script); 484 InitScriptLineEnds(script);
485 AssertNoAllocation no_allocation; 485 AssertNoAllocation no_allocation;
486 FixedArray* line_ends_array = 486 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
487 FixedArray::cast(script->line_ends());
488 const int line_ends_len = line_ends_array->length(); 487 const int line_ends_len = line_ends_array->length();
489 488
490 int line = -1; 489 if (!line_ends_len)
491 if (line_ends_len > 0 && 490 return -1;
492 code_pos <= (Smi::cast(line_ends_array->get(0)))->value()) { 491
493 line = 0; 492 if ((Smi::cast(line_ends_array->get(0)))->value() > code_pos)
494 } else { 493 return script->line_offset()->value();
495 for (int i = 1; i < line_ends_len; ++i) { 494
496 if ((Smi::cast(line_ends_array->get(i - 1)))->value() < code_pos && 495 int left = 0;
497 code_pos <= (Smi::cast(line_ends_array->get(i)))->value()) { 496 int right = line_ends_len;
498 line = i; 497 while (int half = (right - left) / 2) {
499 break; 498 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
500 } 499 right -= half;
500 } else {
501 left += half;
501 } 502 }
502 } 503 }
503 504 return right + script->line_offset()->value();
504 return line != -1 ? line + script->line_offset()->value() : line;
505 } 505 }
506 506
507 507
508 void CustomArguments::IterateInstance(ObjectVisitor* v) { 508 void CustomArguments::IterateInstance(ObjectVisitor* v) {
509 v->VisitPointers(values_, values_ + 4); 509 v->VisitPointers(values_, values_ + 4);
510 } 510 }
511 511
512 512
513 // Compute the property keys from the interceptor. 513 // Compute the property keys from the interceptor.
514 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver, 514 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver,
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 Handle<Map> new_map = Factory::CopyMapDropTransitions(old_map); 828 Handle<Map> new_map = Factory::CopyMapDropTransitions(old_map);
829 obj->set_map(*new_map); 829 obj->set_map(*new_map);
830 new_map->set_needs_loading(true); 830 new_map->set_needs_loading(true);
831 // Store the lazy loading info in the constructor field. We'll 831 // Store the lazy loading info in the constructor field. We'll
832 // reestablish the constructor from the fixed array after loading. 832 // reestablish the constructor from the fixed array after loading.
833 new_map->set_constructor(*arr); 833 new_map->set_constructor(*arr);
834 ASSERT(!obj->IsLoaded()); 834 ASSERT(!obj->IsLoaded());
835 } 835 }
836 836
837 } } // namespace v8::internal 837 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698