diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-05-08 23:21:48 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-05-08 23:21:48 -0600 |
commit | 7a21db5914dd7a5666e603d66ed3948b659ba2fc (patch) | |
tree | bde8e00a1677ba865adae8a82780d1cc832ece8e /libdimension/canvas.c | |
parent | 152362a57dc7fe9dce830ef69118984f854d6375 (diff) | |
download | dimension-7a21db5914dd7a5666e603d66ed3948b659ba2fc.tar.xz |
New DMNSN_ARRAY_FOREACH() macro, faster than iterating with dmnsn_array_get().
Diffstat (limited to 'libdimension/canvas.c')
-rw-r--r-- | libdimension/canvas.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c index 4ed7fd5..2c60c60 100644 --- a/libdimension/canvas.c +++ b/libdimension/canvas.c @@ -48,11 +48,9 @@ dmnsn_delete_canvas(dmnsn_canvas *canvas) { if (canvas) { /* Free the optimizers */ - for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) { - dmnsn_canvas_optimizer optimizer; - dmnsn_array_get(canvas->optimizers, i, &optimizer); - if (optimizer.free_fn) { - (*optimizer.free_fn)(optimizer.ptr); + DMNSN_ARRAY_FOREACH(dmnsn_canvas_optimizer *, i, canvas->optimizers) { + if (i->free_fn) { + (*i->free_fn)(i->ptr); } } dmnsn_delete_array(canvas->optimizers); @@ -75,15 +73,12 @@ void dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, dmnsn_color color) { - dmnsn_canvas_optimizer optimizer; - /* Set the pixel */ canvas->pixels[y*canvas->x + x] = color; /* Call the optimizers */ - for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) { - dmnsn_array_get(canvas->optimizers, i, &optimizer); - (*optimizer.optimizer_fn)(canvas, optimizer, x, y); + DMNSN_ARRAY_FOREACH (dmnsn_canvas_optimizer *, i, canvas->optimizers) { + (*i->optimizer_fn)(canvas, *i, x, y); } } |