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

Unified Diff: src/handles.cc

Issue 1652008: LiveEdit: calculate a real script difference (Closed)
Patch Set: static assert Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/handles.h ('k') | src/liveedit.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/handles.cc
diff --git a/src/handles.cc b/src/handles.cc
index 05cb3f2b383ab32c279e8fe058a572733647c56e..84ee20bba1a7a48f51068814518b459e05e4259b 100644
--- a/src/handles.cc
+++ b/src/handles.cc
@@ -457,6 +457,16 @@ void InitScriptLineEnds(Handle<Script> script) {
}
Handle<String> src(String::cast(script->source()));
+
+ Handle<FixedArray> array = CalculateLineEnds(src, true);
+
+ script->set_line_ends(*array);
+ ASSERT(script->line_ends()->IsFixedArray());
+}
+
+
+Handle<FixedArray> CalculateLineEnds(Handle<String> src,
+ bool with_imaginary_last_new_line) {
const int src_len = src->length();
Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n"));
@@ -468,8 +478,12 @@ void InitScriptLineEnds(Handle<Script> script) {
if (position != -1) {
position++;
}
- // Even if the last line misses a line end, it is counted.
- line_count++;
+ if (position != -1) {
+ line_count++;
+ } else if (with_imaginary_last_new_line) {
+ // Even if the last line misses a line end, it is counted.
+ line_count++;
+ }
}
// Pass 2: Fill in line ends positions
@@ -478,15 +492,17 @@ void InitScriptLineEnds(Handle<Script> script) {
position = 0;
while (position != -1 && position < src_len) {
position = Runtime::StringMatch(src, new_line, position);
- // If the script does not end with a line ending add the final end
- // position as just past the last line ending.
- array->set(array_index++,
- Smi::FromInt(position != -1 ? position++ : src_len));
+ if (position != -1) {
+ array->set(array_index++, Smi::FromInt(position++));
+ } else if (with_imaginary_last_new_line) {
+ // If the script does not end with a line ending add the final end
+ // position as just past the last line ending.
+ array->set(array_index++, Smi::FromInt(src_len));
+ }
}
ASSERT(array_index == line_count);
- script->set_line_ends(*array);
- ASSERT(script->line_ends()->IsFixedArray());
+ return array;
}
« no previous file with comments | « src/handles.h ('k') | src/liveedit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698