Skip to content

Commit 92ef3c1

Browse files
committed
Declare pointers as const when possible
1 parent 9f9bf82 commit 92ef3c1

File tree

9 files changed

+32
-35
lines changed

9 files changed

+32
-35
lines changed

include/twin_private.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ twin_argb32_t *_twin_fetch_argb32(twin_pixmap_t *pixmap,
327327
/*
328328
* Geometry helper functions
329329
*/
330-
twin_dfixed_t _twin_distance_to_point_squared(twin_spoint_t *a,
331-
twin_spoint_t *b);
332-
333330
twin_dfixed_t _twin_distance_to_line_squared(twin_spoint_t *p,
334331
twin_spoint_t *p1,
335332
twin_spoint_t *p2);

src/convolve.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* Find the point in path which is furthest left of the line
1111
*/
1212
static int _twin_path_leftpoint(twin_path_t *path,
13-
twin_spoint_t *p1,
14-
twin_spoint_t *p2)
13+
const twin_spoint_t *p1,
14+
const twin_spoint_t *p2)
1515
{
1616
twin_spoint_t *points = path->points;
1717
int best = 0;
@@ -36,10 +36,10 @@ static int _twin_path_leftpoint(twin_path_t *path,
3636
return best;
3737
}
3838

39-
static int _around_order(twin_spoint_t *a1,
40-
twin_spoint_t *a2,
41-
twin_spoint_t *b1,
42-
twin_spoint_t *b2)
39+
static int _around_order(const twin_spoint_t *a1,
40+
const twin_spoint_t *a2,
41+
const twin_spoint_t *b1,
42+
const twin_spoint_t *b2)
4343
{
4444
twin_dfixed_t adx = (a2->x - a1->x);
4545
twin_dfixed_t ady = (a2->y - a1->y);

src/font.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct _twin_text_info {
2626
} twin_text_info_t;
2727

2828
static void _twin_text_compute_info(twin_path_t *path,
29-
twin_font_t *font,
29+
const twin_font_t *font,
3030
twin_text_info_t *info)
3131
{
3232
twin_spoint_t origin = _twin_path_current_spoint(path);
@@ -175,7 +175,7 @@ static void _twin_text_compute_snap(twin_text_info_t *info,
175175
info->snap_y[s] = FY(snap[s], info);
176176
}
177177

178-
static twin_path_t *_twin_text_compute_pen(twin_text_info_t *info)
178+
static twin_path_t *_twin_text_compute_pen(const twin_text_info_t *info)
179179
{
180180
twin_path_t *pen = twin_path_create();
181181

@@ -184,7 +184,7 @@ static twin_path_t *_twin_text_compute_pen(twin_text_info_t *info)
184184
return pen;
185185
}
186186

187-
static twin_fixed_t _twin_snap(twin_fixed_t v, twin_fixed_t *snap, int n)
187+
static twin_fixed_t _twin_snap(twin_fixed_t v, const twin_fixed_t *snap, int n)
188188
{
189189
for (int s = 0; s < n - 1; s++) {
190190
if (snap[s] <= v && v <= snap[s + 1]) {
@@ -309,7 +309,7 @@ void twin_text_metrics_ucs4(twin_path_t *path,
309309
m->font_descent = font_descent + margin_y;
310310
}
311311

312-
static const signed char *twin_glyph_draw(twin_font_t *font,
312+
static const signed char *twin_glyph_draw(const twin_font_t *font,
313313
const signed char *b)
314314
{
315315
if (font->type == TWIN_FONT_TYPE_STROKE)

src/geom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#include "twin_private.h"
88

9-
twin_dfixed_t _twin_distance_to_point_squared(twin_spoint_t *a,
10-
twin_spoint_t *b)
9+
static twin_dfixed_t _twin_distance_to_point_squared(const twin_spoint_t *a,
10+
const twin_spoint_t *b)
1111
{
1212
twin_dfixed_t dx = (b->x - a->x);
1313
twin_dfixed_t dy = (b->y - a->y);

src/hull.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ typedef struct _twin_hull {
2121
} twin_hull_t;
2222

2323
static void _twin_slope_init(twin_slope_t *slope,
24-
twin_spoint_t *a,
25-
twin_spoint_t *b)
24+
const twin_spoint_t *a,
25+
const twin_spoint_t *b)
2626
{
2727
slope->dx = b->x - a->x;
2828
slope->dy = b->y - a->y;
2929
}
3030

31-
static twin_hull_t *_twin_hull_create(twin_path_t *path, int *nhull)
31+
static twin_hull_t *_twin_hull_create(const twin_path_t *path, int *nhull)
3232
{
3333
int n = path->npoints;
34-
twin_spoint_t *p = path->points;
34+
const twin_spoint_t *p = path->points;
3535
twin_hull_t *hull;
3636

3737
int e = 0;
@@ -77,12 +77,10 @@ static twin_hull_t *_twin_hull_create(twin_path_t *path, int *nhull)
7777
== 0 => a equal to be
7878
> 0 => a more positive than b
7979
*/
80-
static int _twin_slope_compare(twin_slope_t *a, twin_slope_t *b)
80+
static int _twin_slope_compare(const twin_slope_t *a, const twin_slope_t *b)
8181
{
82-
twin_dfixed_t diff;
83-
84-
diff = ((twin_dfixed_t) a->dy * (twin_dfixed_t) b->dx -
85-
(twin_dfixed_t) b->dy * (twin_dfixed_t) a->dx);
82+
twin_dfixed_t diff = ((twin_dfixed_t) a->dy * (twin_dfixed_t) b->dx -
83+
(twin_dfixed_t) b->dy * (twin_dfixed_t) a->dx);
8684

8785
if (diff > 0)
8886
return 1;
@@ -125,7 +123,7 @@ static int _twin_hull_vertex_compare(const void *av, const void *bv)
125123
return ret;
126124
}
127125

128-
static int _twin_hull_prev_valid(twin_hull_t *hull,
126+
static int _twin_hull_prev_valid(const twin_hull_t *hull,
129127
int maybe_unused num_hull,
130128
int index)
131129
{
@@ -137,7 +135,9 @@ static int _twin_hull_prev_valid(twin_hull_t *hull,
137135
return index;
138136
}
139137

140-
static int _twin_hull_next_valid(twin_hull_t *hull, int num_hull, int index)
138+
static int _twin_hull_next_valid(const twin_hull_t *hull,
139+
int num_hull,
140+
int index)
141141
{
142142
do {
143143
index = (index + 1) % num_hull;
@@ -180,7 +180,7 @@ static void _twin_hull_eliminate_concave(twin_hull_t *hull, int num_hull)
180180
/*
181181
* Convert the hull structure back to a simple path
182182
*/
183-
static twin_path_t *_twin_hull_to_path(twin_hull_t *hull, int num_hull)
183+
static twin_path_t *_twin_hull_to_path(const twin_hull_t *hull, int num_hull)
184184
{
185185
twin_path_t *path = twin_path_create();
186186

src/screen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ static void twin_screen_update_cursor(twin_screen_t *screen,
307307
}
308308
#endif /* CONFIG_CURSOR */
309309

310-
static void _twin_adj_mouse_evt(twin_event_t *event, twin_pixmap_t *pixmap)
310+
static void _twin_adj_mouse_evt(twin_event_t *event,
311+
const twin_pixmap_t *pixmap)
311312
{
312313
event->u.pointer.x = event->u.pointer.screen_x - pixmap->x;
313314
event->u.pointer.y = event->u.pointer.screen_y - pixmap->y;

src/spline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ typedef struct _twin_spline {
1515
* The shift factor determines the position between 'a' and 'b'.
1616
* The result is stored in 'result'.
1717
*/
18-
static void _lerp(twin_spoint_t *a,
19-
twin_spoint_t *b,
18+
static void _lerp(const twin_spoint_t *a,
19+
const twin_spoint_t *b,
2020
int shift,
2121
twin_spoint_t *result)
2222
{

src/timeout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ static twin_time_t start;
2424

2525
static twin_order_t _twin_timeout_order(twin_queue_t *a, twin_queue_t *b)
2626
{
27-
twin_timeout_t *at = (twin_timeout_t *) a;
28-
twin_timeout_t *bt = (twin_timeout_t *) b;
27+
const twin_timeout_t *at = (twin_timeout_t *) a;
28+
const twin_timeout_t *bt = (twin_timeout_t *) b;
2929

3030
if (twin_time_compare(at->time, <, bt->time))
3131
return TWIN_BEFORE;
@@ -85,7 +85,7 @@ void twin_clear_timeout(twin_timeout_t *timeout)
8585
twin_time_t _twin_timeout_delay(void)
8686
{
8787
if (head) {
88-
twin_timeout_t *thead = (twin_timeout_t *) head;
88+
const twin_timeout_t *thead = (twin_timeout_t *) head;
8989
twin_time_t now = twin_now();
9090
if (twin_time_compare(now, >=, thead->time))
9191
return 0;

src/work.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ static twin_queue_t *head;
1212

1313
static twin_order_t _twin_work_order(twin_queue_t *a, twin_queue_t *b)
1414
{
15-
twin_work_t *aw = (twin_work_t *) a;
16-
twin_work_t *bw = (twin_work_t *) b;
15+
const twin_work_t *aw = (twin_work_t *) a, *bw = (twin_work_t *) b;
1716

1817
if (aw->priority < bw->priority)
1918
return TWIN_BEFORE;

0 commit comments

Comments
 (0)