Skip to content

Commit 949b527

Browse files
committed
Use C99 designated initializers when possible
1 parent be8ad54 commit 949b527

File tree

7 files changed

+17
-34
lines changed

7 files changed

+17
-34
lines changed

src/font.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ static twin_path_t *_twin_text_compute_pen(twin_text_info_t *info)
186186

187187
static twin_fixed_t _twin_snap(twin_fixed_t v, twin_fixed_t *snap, int n)
188188
{
189-
int s;
190-
191-
for (s = 0; s < n - 1; s++) {
189+
for (int s = 0; s < n - 1; s++) {
192190
if (snap[s] <= v && v <= snap[s + 1]) {
193191
twin_fixed_t before = snap[s];
194192
twin_fixed_t after = snap[s + 1];

src/path.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,7 @@ void twin_path_bounds(twin_path_t *path, twin_rect_t *rect)
410410

411411
void twin_path_append(twin_path_t *dst, twin_path_t *src)
412412
{
413-
int p;
414-
int s = 0;
415-
416-
for (p = 0; p < src->npoints; p++) {
413+
for (int p = 0, s = 0; p < src->npoints; p++) {
417414
if (s < src->nsublen && p == src->sublen[s]) {
418415
_twin_path_sfinish(dst);
419416
s++;
@@ -463,33 +460,26 @@ void twin_composite_path(twin_pixmap_t *dst,
463460
twin_operator_t operator)
464461
{
465462
twin_rect_t bounds;
466-
twin_pixmap_t *mask;
467-
twin_operand_t msk;
468-
twin_coord_t width, height;
469-
470463
twin_path_bounds(path, &bounds);
471464
if (bounds.left >= bounds.right || bounds.top >= bounds.bottom)
472465
return;
473-
width = bounds.right - bounds.left;
474-
height = bounds.bottom - bounds.top;
475-
mask = twin_pixmap_create(TWIN_A8, width, height);
476466

467+
twin_coord_t width = bounds.right - bounds.left;
468+
twin_coord_t height = bounds.bottom - bounds.top;
469+
twin_pixmap_t *mask = twin_pixmap_create(TWIN_A8, width, height);
477470
if (!mask)
478471
return;
472+
479473
twin_fill_path(mask, path, -bounds.left, -bounds.top);
480-
msk.source_kind = TWIN_PIXMAP;
481-
msk.u.pixmap = mask;
474+
twin_operand_t msk = {.source_kind = TWIN_PIXMAP, .u.pixmap = mask};
482475
twin_composite(dst, bounds.left, bounds.top, src, src_x + bounds.left,
483476
src_y + bounds.top, &msk, 0, 0, operator, width, height);
484477
twin_pixmap_destroy(mask);
485478
}
486479

487480
void twin_paint_path(twin_pixmap_t *dst, twin_argb32_t argb, twin_path_t *path)
488481
{
489-
twin_operand_t src;
490-
491-
src.source_kind = TWIN_SOLID;
492-
src.u.argb = argb;
482+
twin_operand_t src = {.source_kind = TWIN_SOLID, .u.argb = argb};
493483
twin_composite_path(dst, &src, 0, 0, path, TWIN_OVER);
494484
}
495485

@@ -521,9 +511,6 @@ void twin_paint_stroke(twin_pixmap_t *dst,
521511
twin_path_t *stroke,
522512
twin_fixed_t pen_width)
523513
{
524-
twin_operand_t src;
525-
526-
src.source_kind = TWIN_SOLID;
527-
src.u.argb = argb;
514+
twin_operand_t src = {.source_kind = TWIN_SOLID, .u.argb = argb};
528515
twin_composite_stroke(dst, &src, 0, 0, stroke, pen_width, TWIN_OVER);
529516
}

src/poly.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,11 @@ void twin_fill_path(twin_pixmap_t *pixmap,
305305
int nedges = 0;
306306
for (int s = 0; s <= path->nsublen; s++) {
307307
int sublen;
308-
int npoints;
309-
310308
if (s == path->nsublen)
311309
sublen = path->npoints;
312310
else
313311
sublen = path->sublen[s];
314-
npoints = sublen - p;
312+
int npoints = sublen - p;
315313
if (npoints > 1) {
316314
int n =
317315
_twin_edge_build(path->points + p, npoints, edges + nedges, sdx,

src/queue.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ void _twin_queue_delete(twin_queue_t **head, twin_queue_t *old)
6161
twin_queue_t *_twin_queue_set_order(twin_queue_t **head)
6262
{
6363
twin_queue_t *first = *head;
64-
twin_queue_t *q;
6564

66-
for (q = first; q; q = q->next) {
65+
for (twin_queue_t *q = first; q; q = q->next) {
6766
q->order = q->next;
6867
q->walking = true;
6968
}

src/toplevel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ twin_toplevel_t *twin_toplevel_create(twin_screen_t *screen,
8484
twin_window_create(screen, format, style, x, y, width, height);
8585

8686
if (!window)
87-
return 0;
87+
return NULL;
8888
toplevel = malloc(sizeof(twin_toplevel_t) + strlen(name) + 1);
8989
if (!toplevel) {
9090
twin_window_destroy(window);
91-
return 0;
91+
return NULL;
9292
}
9393
_twin_toplevel_init(toplevel, _twin_toplevel_dispatch, window, name);
9494
return toplevel;

src/trig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static inline twin_fixed_t sin_poly(twin_angle_t x)
5959
y = x * (y >> n);
6060
y = A1 - (y >> (p - q));
6161
y = x * (y >> n);
62-
y = (y + (1UL << (q - A - 1))) >> (q - A); // Rounding
62+
y = (y + (1UL << (q - A - 1))) >> (q - A); /* Rounding */
6363
return y;
6464
}
6565

src/widget.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ static twin_path_t *_twin_path_shape(twin_shape_t shape,
1616
twin_fixed_t radius)
1717
{
1818
twin_path_t *path = twin_path_create();
19+
if (!path)
20+
return NULL;
21+
1922
twin_fixed_t x = twin_int_to_fixed(left);
2023
twin_fixed_t y = twin_int_to_fixed(top);
2124
twin_fixed_t w = twin_int_to_fixed(right - left);
2225
twin_fixed_t h = twin_int_to_fixed(bottom - top);
2326

24-
if (!path)
25-
return 0;
2627
switch (shape) {
2728
case TwinShapeRectangle:
2829
twin_path_rectangle(path, x, y, w, h);

0 commit comments

Comments
 (0)