Index: src/messages.js |
=================================================================== |
--- src/messages.js (revision 3373) |
+++ src/messages.js (working copy) |
@@ -238,14 +238,15 @@ |
Script.prototype.lineFromPosition = function(position) { |
var lower = 0; |
var upper = this.lineCount() - 1; |
+ var line_ends = this.line_ends; |
// We'll never find invalid positions so bail right away. |
- if (position > this.line_ends[upper]) { |
+ if (position > line_ends[upper]) { |
return -1; |
} |
// This means we don't have to safe-guard indexing line_ends[i - 1]. |
- if (position <= this.line_ends[0]) { |
+ if (position <= line_ends[0]) { |
return 0; |
} |
@@ -253,9 +254,9 @@ |
while (upper >= 1) { |
var i = (lower + upper) >> 1; |
- if (position > this.line_ends[i]) { |
+ if (position > line_ends[i]) { |
lower = i + 1; |
- } else if (position <= this.line_ends[i - 1]) { |
+ } else if (position <= line_ends[i - 1]) { |
upper = i - 1; |
} else { |
return i; |
@@ -278,8 +279,9 @@ |
if (line == -1) return null; |
// Determine start, end and column. |
- var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; |
- var end = this.line_ends[line]; |
+ var line_ends = this.line_ends; |
+ var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
+ var end = line_ends[line]; |
if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; |
var column = position - start; |
@@ -368,8 +370,9 @@ |
return null; |
} |
- var from_position = from_line == 0 ? 0 : this.line_ends[from_line - 1] + 1; |
- var to_position = to_line == 0 ? 0 : this.line_ends[to_line - 1] + 1; |
+ var line_ends = this.line_ends; |
+ var from_position = from_line == 0 ? 0 : line_ends[from_line - 1] + 1; |
+ var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1; |
// Return a source slice with line numbers re-adjusted to the resource. |
return new SourceSlice(this, from_line + this.line_offset, to_line + this.line_offset, |
@@ -391,8 +394,9 @@ |
} |
// Return the source line. |
- var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; |
- var end = this.line_ends[line]; |
+ var line_ends = this.line_ends; |
+ var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
+ var end = line_ends[line]; |
return StringSubstring.call(this.source, start, end); |
} |