History

table: use sl_offsetof instead of doing arithmetic with sizeof

Sigrid Solveig Haflínudóttir committed 4 months ago

Commit b7cbfee1 parent bfd54071 file · +2 −4Browse files

Unified · Split

src/table.c+2−4
@@ -6,8 +6,6 @@ · 5 unmodified lines
66 #include "print.h"
77 #include "table.h"
88
9−#define inline_space sizeof(((sl_htable*)nil)->_space)
10−
119 static const sl_type *sl_tabletype;
1210
1311 sl_nonnull(2)
@@ -131,7 +129,7 @@ BUILTIN("table", table) · 117 unmodified lines
131129 if(cnt <= HT_N_INLINE)
132130 nt = cvalue_nofinalizer(sl_tabletype, sizeof(sl_htable));
133131 else
134− nt = cvalue(sl_tabletype, sizeof(sl_htable)-inline_space);
132+ nt = cvalue(sl_tabletype, sl_offsetof(sl_htable, _space));
135133 sl_htable *h = cvalue_data(nt);
136134 htable_new(h, cnt/2);
137135 sl_v k = sl_nil, arg;
@@ -156,7 +154,7 @@ BUILTIN("put!", put) · 18 unmodified lines
156154 if(table0 == &h->_space[0] && h->table != &h->_space[0]){
157155 sl_cv *cv = ptr(sl_cv, args[0]);
158156 add_finalizer(cv);
159− cv->len = sizeof(sl_htable) - inline_space;
157+ cv->len = sl_offsetof(sl_htable, _space);
160158 }
161159 return args[0];
162160 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t