Skip to content

Commit

Permalink
Improve performance of location data compensation (#5294)
Browse files Browse the repository at this point in the history
  • Loading branch information
helixbass authored and GeoffreyBooth committed Jan 27, 2020
1 parent bb8df1e commit 6fe980e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
24 changes: 13 additions & 11 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1033,14 +1033,17 @@ exports.Lexer = class Lexer
# Compensate for the things we strip out initially (e.g. carriage returns)
# so that location data stays accurate with respect to the original source file.
getLocationDataCompensation: (start, end) ->
compensation = 0
totalCompensation = 0
initialEnd = end
for index, length of @locationDataCompensations
index = parseInt index, 10
continue unless start <= index and (index < end or index is end and start is initialEnd)
compensation += length
end += length
compensation
current = start
while current <= end
break if current is end and start isnt initialEnd
compensation = @locationDataCompensations[current]
if compensation?
totalCompensation += compensation
end += compensation
current++
return totalCompensation

# Returns the line and column number from an offset into the current chunk.
#
Expand Down

0 comments on commit 6fe980e

Please sign in to comment.