Skip to content

Commit d7dfbbd

Browse files
committed
Encapsulate FBuffer uses
1 parent 7d74243 commit d7dfbbd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ext/json/ext/fbuffer/fbuffer.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ static inline void fbuffer_append_char(FBuffer *fb, char newchr)
175175
fb->len++;
176176
}
177177

178+
static inline char *fbuffer_cursor(FBuffer *fb)
179+
{
180+
return fb->ptr + fb->len;
181+
}
182+
183+
static inline void fbuffer_advance_to(FBuffer *fb, char *end)
184+
{
185+
fb->len = end - fb->ptr;
186+
}
187+
178188
/*
179189
* Appends the decimal string representation of \a number into the buffer.
180190
*/
@@ -205,9 +215,8 @@ static void fbuffer_append_long(FBuffer *fb, long number)
205215
number = -number;
206216
}
207217

208-
char* d = fb->ptr + fb->len;
209-
char* end = jeaiii_ultoa(d, number);
210-
fb->len += end - d;
218+
char *end = jeaiii_ultoa(fbuffer_cursor(fb), number);
219+
fbuffer_advance_to(fb, end);
211220
}
212221

213222
static VALUE fbuffer_finalize(FBuffer *fb)

0 commit comments

Comments
 (0)