From 1486e5a9e0b47f28f845c042ef303ca440b9783c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 11 Jun 2025 23:11:20 +0100 Subject: [PATCH] avoid reffing g:line_to in loop it makes a difference on the flame graph but not a noticeable one in top --- pkgs/maps/main.fnl | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index ae66529..4b4b0f2 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -150,38 +150,38 @@ label.readout { (local cq (cqueues.new)) -(fn road-width-for [line offset] - (+ (or offset 0) - (case (?. line :tags :highway) - :motorway 18 - :trunk 17 - :primary 16 - :secondary 14 - :cycleway 4 - :footway 4 - other 12))) - -(fn cairo-road-path [g [[sx sy] & points] bounds width] - (g:save) - (g:set_line_width width) - (g:move_to (* tile-size (- sx bounds.min.x)) - (* tile-size (- sy bounds.min.y))) - (each [_ [x y] (ipairs points)] - (let [x1 (* tile-size (- x bounds.min.x)) - y1 (* tile-size (- y bounds.min.y))] - (g:line_to x1 y1))) - (g:stroke) - (g:restore)) +(fn road-width-for [line] + (case (?. line :tags :highway) + :motorway 18 + :trunk 17 + :primary 16 + :secondary 14 + :cycleway 4 + :footway 4 + other 12)) +(fn cairo-road-path [g [[sx sy] & points] bounds] + (let [min bounds.min + { : line_to } g] + (g:move_to (* tile-size (- sx min.x)) + (* tile-size (- sy min.y))) + (each [_ [x y] (ipairs points)] + (let [x1 (* tile-size (- x min.x)) + y1 (* tile-size (- y min.y))] + (line_to g x1 y1))))) (fn cairo-roads [g lines bounds] - (let [road-width 14] - (g:set_source_rgb 0 0 0) - (each [_ line (pairs lines)] - (cairo-road-path g line.points bounds (road-width-for line))) - (g:set_source_rgb 1 1 1) - (each [_ line (pairs lines)] - (cairo-road-path g line.points bounds (road-width-for line -2))))) + (g:set_source_rgb 0 0 0) + (each [_ line (pairs lines)] + (g:set_line_width (road-width-for line)) + (cairo-road-path g line.points bounds ) + (g:stroke)) + (g:set_source_rgb 1 1 1) + (each [_ line (pairs lines)] + (g:set_line_width (- (road-width-for line) 2)) + (cairo-road-path g line.points bounds) + (g:stroke))) + (var map-surface nil)