From 76da6ec140cbbdac6136469ce50aab40e218f398 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 29 Jul 2023 16:06:19 +0100 Subject: js: keep colour strings in JavaScript rather than in C The drawing routines in JavaScript used to take pointers to a C string containing a CSS colour name. That meant that JavaScript had to create a new JavaScript string on ever call to a drawing function, which seemed ugly. So now we instead pass colour numbers all the way down into JavaScript and keep an array of JavaScript strings there that can be re-used. The conversion from RGB triples to strings is still done in C, though. This doesn't seem to have fixed either of the bugs I hoped it would, but it does measurably improve drawing performance so I think it's worth doing. --- emccpre.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'emccpre.js') diff --git a/emccpre.js b/emccpre.js index de94509..3869060 100644 --- a/emccpre.js +++ b/emccpre.js @@ -41,6 +41,10 @@ var ctx; // by js_canvas_end_draw. var update_xmin, update_xmax, update_ymin, update_ymax; +// Colour strings to use when drawing, to save converting them from C +// every time. +var colours = []; + // Module object for Emscripten. We fill in these parameters to ensure // that when main() returns nothing will get cleaned up so we remain // able to call the puzzle's various callbacks. -- cgit v1.1