Skip to content

Commit 6fe980e

Browse files
helixbassGeoffreyBooth
authored andcommitted
Improve performance of location data compensation (#5294)
1 parent bb8df1e commit 6fe980e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

lib/coffeescript/lexer.js

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,14 +1033,17 @@ exports.Lexer = class Lexer
10331033
# Compensate for the things we strip out initially (e.g. carriage returns)
10341034
# so that location data stays accurate with respect to the original source file.
10351035
getLocationDataCompensation: (start, end) ->
1036-
compensation = 0
1036+
totalCompensation = 0
10371037
initialEnd = end
1038-
for index, length of @locationDataCompensations
1039-
index = parseInt index, 10
1040-
continue unless start <= index and (index < end or index is end and start is initialEnd)
1041-
compensation += length
1042-
end += length
1043-
compensation
1038+
current = start
1039+
while current <= end
1040+
break if current is end and start isnt initialEnd
1041+
compensation = @locationDataCompensations[current]
1042+
if compensation?
1043+
totalCompensation += compensation
1044+
end += compensation
1045+
current++
1046+
return totalCompensation
10441047

10451048
# Returns the line and column number from an offset into the current chunk.
10461049
#

0 commit comments

Comments
 (0)