Skip to content

Commit

Permalink
🐎 Speed up decorations retrieval when rendering lines
Browse files Browse the repository at this point in the history
There’s no longer a loop each time we need to get decorations of a
given type for a given row, everything was already computed in the
`minimap.decorationsForScreenRowRangeByRowAndType` method.
  • Loading branch information
abe33 committed Feb 26, 2015
1 parent cf87846 commit ad4b33b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/mixins/canvas-drawer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CanvasDrawer extends Mixin
charWidth = @minimap.getCharWidth() * devicePixelRatio
canvasWidth = @canvas.width
displayCodeHighlights = @displayCodeHighlights
decorations = @minimap.decorationsForScreenRowRange(firstRow, lastRow)
decorations = @minimap.decorationsForScreenRowRangeByRowAndType(firstRow, lastRow)

line = lines[0]

Expand All @@ -155,13 +155,15 @@ class CanvasDrawer extends Mixin
y0 = y*lineHeight

# Line decorations are first drawn on the canvas.
lineDecorations = @minimap.decorationsByTypesForRow(screenRow, 'line', decorations)
@drawLineDecorations(context, lineDecorations, y0, canvasWidth, lineHeight) if lineDecorations.length
lineDecorations = decorations['line']?[screenRow]

@drawLineDecorations(context, lineDecorations, y0, canvasWidth, lineHeight) if lineDecorations?.length

# Then comes the highlight decoration with `highlight-under` type.
highlightDecorations = @minimap.decorationsByTypesForRow(firstRow + row, 'highlight-under', decorations)
for decoration in highlightDecorations
@drawHighlightDecoration(context, decoration, y, screenRow, lineHeight, charWidth, canvasWidth)
highlightDecorations = decorations['highlight-under']?[firstRow + row]
if highlightDecorations?.length
for decoration in highlightDecorations
@drawHighlightDecoration(context, decoration, y, screenRow, lineHeight, charWidth, canvasWidth)

# Then the line tokens are drawn
for token in line.tokens
Expand All @@ -182,9 +184,10 @@ class CanvasDrawer extends Mixin
break if x > canvasWidth

# Finally the highlight over decorations are drawn.
highlightDecorations = @minimap.decorationsByTypesForRow(firstRow + row, 'highlight', 'highlight-over', decorations)
for decoration in highlightDecorations
@drawHighlightDecoration(context, decoration, y, screenRow, lineHeight, charWidth, canvasWidth)
highlightDecorations = decorations['highlight-over']?[firstRow + row]
if highlightDecorations?.length
for decoration in highlightDecorations
@drawHighlightDecoration(context, decoration, y, screenRow, lineHeight, charWidth, canvasWidth)

context.fill()

Expand Down

0 comments on commit ad4b33b

Please sign in to comment.