LiveEdit: optimize substring comparison

Review URL: http://codereview.chromium.org/6899011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7710 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
peter.rybin@gmail.com 2011-04-28 20:24:47 +00:00
parent f7ecf95e95
commit e04dd7199e
2 changed files with 9 additions and 25 deletions

View File

@ -871,14 +871,6 @@ class Isolate {
RuntimeState* runtime_state() { return &runtime_state_; }
StringInputBuffer* liveedit_compare_substrings_buf1() {
return &liveedit_compare_substrings_buf1_;
}
StringInputBuffer* liveedit_compare_substrings_buf2() {
return &liveedit_compare_substrings_buf2_;
}
StaticResource<SafeStringInputBuffer>* compiler_safe_string_input_buffer() {
return &compiler_safe_string_input_buffer_;
}
@ -1144,8 +1136,6 @@ class Isolate {
ThreadManager* thread_manager_;
AstSentinels* ast_sentinels_;
RuntimeState runtime_state_;
StringInputBuffer liveedit_compare_substrings_buf1_;
StringInputBuffer liveedit_compare_substrings_buf2_;
StaticResource<SafeStringInputBuffer> compiler_safe_string_input_buffer_;
Builtins builtins_;
StringTracker* string_tracker_;

View File

@ -268,17 +268,10 @@ void Comparator::CalculateDifference(Comparator::Input* input,
}
static bool CompareSubstrings(Isolate* isolate, Handle<String> s1, int pos1,
static bool CompareSubstrings(Handle<String> s1, int pos1,
Handle<String> s2, int pos2, int len) {
StringInputBuffer& buf1 = *isolate->liveedit_compare_substrings_buf1();
StringInputBuffer& buf2 = *isolate->liveedit_compare_substrings_buf2();
buf1.Reset(*s1);
buf1.Seek(pos1);
buf2.Reset(*s2);
buf2.Seek(pos2);
for (int i = 0; i < len; i++) {
ASSERT(buf1.has_more() && buf2.has_more());
if (buf1.GetNext() != buf2.GetNext()) {
if (s1->Get(i + pos1) != s2->Get(i + pos2)) {
return false;
}
}
@ -410,9 +403,9 @@ class LineEndsWrapper {
// Represents 2 strings as 2 arrays of lines.
class LineArrayCompareInput : public Comparator::Input {
public:
LineArrayCompareInput(Isolate* isolate, Handle<String> s1, Handle<String> s2,
LineArrayCompareInput(Handle<String> s1, Handle<String> s2,
LineEndsWrapper line_ends1, LineEndsWrapper line_ends2)
: isolate_(isolate), s1_(s1), s2_(s2), line_ends1_(line_ends1),
: s1_(s1), s2_(s2), line_ends1_(line_ends1),
line_ends2_(line_ends2) {
}
int getLength1() {
@ -431,12 +424,11 @@ class LineArrayCompareInput : public Comparator::Input {
if (len1 != len2) {
return false;
}
return CompareSubstrings(isolate_, s1_, line_start1, s2_, line_start2,
return CompareSubstrings(s1_, line_start1, s2_, line_start2,
len1);
}
private:
Isolate* isolate_;
Handle<String> s1_;
Handle<String> s2_;
LineEndsWrapper line_ends1_;
@ -492,11 +484,13 @@ class TokenizingLineArrayCompareOutput : public Comparator::Output {
Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1,
Handle<String> s2) {
s1 = FlattenGetString(s1);
s2 = FlattenGetString(s2);
LineEndsWrapper line_ends1(s1);
LineEndsWrapper line_ends2(s2);
LineArrayCompareInput
input(Isolate::Current(), s1, s2, line_ends1, line_ends2);
LineArrayCompareInput input(s1, s2, line_ends1, line_ends2);
TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2);
Comparator::CalculateDifference(&input, &output);