5 ms·
> why are the flag values not enums (and why is 4 missing?)? What would the advantage of using an enum be? (and I guess I used 4 and then removed it later.) >
by udp 15y ago
> why are the flag values not enums (and why is 4 missing?)?
What would the advantage of using an enum be? (and I guess I used 4 and then removed it later.)
> is using a lookup table for decoding hex really faster than the (minimal) logic (what if it causes cache misses)?
No idea, that's just the way I did it. Feel free to try something else and profile if you're really that concerned.
> do you really think that a state machine with bit flags is the best way to express the logic here? is string_add meant to increment string_length on subsequent passes?
There's only two passes, and it increments the length on both (the first is to measure the string, the second is to know where to write in it).
> what is "[..] cur_value" supposed to do at the top of json_value_free (maybe i am missing some c trick here?)?
You're not supposed to mix code and value declarations in ANSI C, so I put it at the top of the function. It's just used to temporarily store the value while reading the parent.
- andrewcooke 15y agoha. on the last one i was confused by your spaces - thought it was a multiplication... (sorry) [edit] on the bitfield / enum question, i've been looking around for a consistent, standard way of doing things and there doesn't seem to be any one best practice (although various people note that bit fields are normally unsigned ints, while enums are signed).
- parenthesis 15y ago> You're not supposed to mix code and value declarations in ANSI C You can in C99.
- nknight 15y agoIn ordinary usage, "ANSI C" is a synonym for strict C89. C99 is not well-supported by many compilers, so code intended to be widely portable is still frequently written to strict C89.
- pjscott 15y agoI've converted the lookup table to a few lines of logic. I think it's more readable, and I would definitely bet on it being faster, though since I haven't profiled I don't know how much difference it would make. https://github.com/PeterScott/json-parser/commit/db9c326f74709b5a5f2904e11f44b9c165613433 https://github.com/PeterScott/json-parser/commit/db9c326f747...
- udp 15y agoYeah, I'll go with that - cheers.