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
6#include "print.h"6#include "print.h"
7#include "table.h"7#include "table.h"
8 8
9#define inline_space sizeof(((sl_htable*)nil)->_space)
10
11static const sl_type *sl_tabletype;9static const sl_type *sl_tabletype;
12 10
13sl_nonnull(2)11sl_nonnull(2)
@@ -131,7 +129,7 @@ BUILTIN("table", table) · 117 unmodified lines
131 if(cnt <= HT_N_INLINE)129 if(cnt <= HT_N_INLINE)
132 nt = cvalue_nofinalizer(sl_tabletype, sizeof(sl_htable));130 nt = cvalue_nofinalizer(sl_tabletype, sizeof(sl_htable));
133 else131 else
134 nt = cvalue(sl_tabletype, sizeof(sl_htable)-inline_space);132 nt = cvalue(sl_tabletype, sl_offsetof(sl_htable, _space));
135 sl_htable *h = cvalue_data(nt);133 sl_htable *h = cvalue_data(nt);
136 htable_new(h, cnt/2);134 htable_new(h, cnt/2);
137 sl_v k = sl_nil, arg;135 sl_v k = sl_nil, arg;
@@ -156,7 +154,7 @@ BUILTIN("put!", put) · 18 unmodified lines
156 if(table0 == &h->_space[0] && h->table != &h->_space[0]){154 if(table0 == &h->_space[0] && h->table != &h->_space[0]){
157 sl_cv *cv = ptr(sl_cv, args[0]);155 sl_cv *cv = ptr(sl_cv, args[0]);
158 add_finalizer(cv);156 add_finalizer(cv);
159 cv->len = sizeof(sl_htable) - inline_space;157 cv->len = sl_offsetof(sl_htable, _space);
160 }158 }
161 return args[0];159 return args[0];
162}160}

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