Commit e04dd719 authored by peter.rybin@gmail.com's avatar peter.rybin@gmail.com

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
parent f7ecf95e
...@@ -871,14 +871,6 @@ class Isolate { ...@@ -871,14 +871,6 @@ class Isolate {
RuntimeState* runtime_state() { return &runtime_state_; } 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() { StaticResource<SafeStringInputBuffer>* compiler_safe_string_input_buffer() {
return &compiler_safe_string_input_buffer_; return &compiler_safe_string_input_buffer_;
} }
...@@ -1144,8 +1136,6 @@ class Isolate { ...@@ -1144,8 +1136,6 @@ class Isolate {
ThreadManager* thread_manager_; ThreadManager* thread_manager_;
AstSentinels* ast_sentinels_; AstSentinels* ast_sentinels_;
RuntimeState runtime_state_; RuntimeState runtime_state_;
StringInputBuffer liveedit_compare_substrings_buf1_;
StringInputBuffer liveedit_compare_substrings_buf2_;
StaticResource<SafeStringInputBuffer> compiler_safe_string_input_buffer_; StaticResource<SafeStringInputBuffer> compiler_safe_string_input_buffer_;
Builtins builtins_; Builtins builtins_;
StringTracker* string_tracker_; StringTracker* string_tracker_;
......
...@@ -268,17 +268,10 @@ void Comparator::CalculateDifference(Comparator::Input* input, ...@@ -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) { 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++) { for (int i = 0; i < len; i++) {
ASSERT(buf1.has_more() && buf2.has_more()); if (s1->Get(i + pos1) != s2->Get(i + pos2)) {
if (buf1.GetNext() != buf2.GetNext()) {
return false; return false;
} }
} }
...@@ -410,9 +403,9 @@ class LineEndsWrapper { ...@@ -410,9 +403,9 @@ class LineEndsWrapper {
// Represents 2 strings as 2 arrays of lines. // Represents 2 strings as 2 arrays of lines.
class LineArrayCompareInput : public Comparator::Input { class LineArrayCompareInput : public Comparator::Input {
public: public:
LineArrayCompareInput(Isolate* isolate, Handle<String> s1, Handle<String> s2, LineArrayCompareInput(Handle<String> s1, Handle<String> s2,
LineEndsWrapper line_ends1, LineEndsWrapper line_ends2) 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) { line_ends2_(line_ends2) {
} }
int getLength1() { int getLength1() {
...@@ -431,12 +424,11 @@ class LineArrayCompareInput : public Comparator::Input { ...@@ -431,12 +424,11 @@ class LineArrayCompareInput : public Comparator::Input {
if (len1 != len2) { if (len1 != len2) {
return false; return false;
} }
return CompareSubstrings(isolate_, s1_, line_start1, s2_, line_start2, return CompareSubstrings(s1_, line_start1, s2_, line_start2,
len1); len1);
} }
private: private:
Isolate* isolate_;
Handle<String> s1_; Handle<String> s1_;
Handle<String> s2_; Handle<String> s2_;
LineEndsWrapper line_ends1_; LineEndsWrapper line_ends1_;
...@@ -492,11 +484,13 @@ class TokenizingLineArrayCompareOutput : public Comparator::Output { ...@@ -492,11 +484,13 @@ class TokenizingLineArrayCompareOutput : public Comparator::Output {
Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1, Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1,
Handle<String> s2) { Handle<String> s2) {
s1 = FlattenGetString(s1);
s2 = FlattenGetString(s2);
LineEndsWrapper line_ends1(s1); LineEndsWrapper line_ends1(s1);
LineEndsWrapper line_ends2(s2); LineEndsWrapper line_ends2(s2);
LineArrayCompareInput LineArrayCompareInput input(s1, s2, line_ends1, line_ends2);
input(Isolate::Current(), s1, s2, line_ends1, line_ends2);
TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2); TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2);
Comparator::CalculateDifference(&input, &output); Comparator::CalculateDifference(&input, &output);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment