Skip to content

Commit 24f219d

Browse files
committed
Temporary change: no unaligned access when parsing json
Signed-off-by: Björn Svensson <[email protected]>
1 parent 1ea6a99 commit 24f219d

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

include/flatcc/flatcc_json_parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,10 @@ static inline uint64_t flatcc_json_parser_symbol_part(const char *buf, const cha
307307
{
308308
size_t n = (size_t)(end - buf);
309309

310-
#if FLATCC_ALLOW_UNALIGNED_ACCESS
311-
if (n >= 8) {
310+
/* Read directly if the word is aligned. */
311+
if (n >= 8 && ((uintptr_t)buf % 8) == 0) {
312312
return be64toh(*(uint64_t *)buf);
313313
}
314-
#endif
315314
return flatcc_json_parser_symbol_part_ext(buf, end);
316315
}
317316

src/runtime/json_parser.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,39 +103,39 @@ const char *flatcc_json_parser_space_ext(flatcc_json_parser_t *ctx, const char *
103103
*/
104104
//cmpistri(end, buf, "\x20\t\v\f\r\n", _SIDD_NEGATIVE_POLARITY);
105105
cmpistri(end, buf, "\x20\t\v\f", _SIDD_NEGATIVE_POLARITY);
106-
#else
107-
#if FLATCC_ALLOW_UNALIGNED_ACCESS
108-
while (end - buf >= 16) {
109-
if (*buf > 0x20) {
110-
return buf;
111-
}
112-
#if FLATCC_JSON_PARSE_WIDE_SPACE
113-
if (((uint64_t *)buf)[0] != 0x2020202020202020) {
114-
descend:
115-
if (((uint32_t *)buf)[0] == 0x20202020) {
116-
buf += 4;
117-
}
118-
#endif
119-
if (((uint16_t *)buf)[0] == 0x2020) {
120-
buf += 2;
121-
}
122-
if (*buf == 0x20) {
123-
++buf;
124-
}
125-
if (*buf > 0x20) {
126-
return buf;
127-
}
128-
break;
129-
#if FLATCC_JSON_PARSE_WIDE_SPACE
130-
}
131-
if (((uint64_t *)buf)[1] != 0x2020202020202020) {
132-
buf += 8;
133-
goto descend;
134-
}
135-
buf += 16;
136-
#endif
137-
}
138-
#endif
106+
//#else
107+
//#if FLATCC_ALLOW_UNALIGNED_ACCESS
108+
// while (end - buf >= 16) {
109+
// if (*buf > 0x20) {
110+
// return buf;
111+
// }
112+
//#if FLATCC_JSON_PARSE_WIDE_SPACE
113+
// if (((uint64_t *)buf)[0] != 0x2020202020202020) {
114+
//descend:
115+
// if (((uint32_t *)buf)[0] == 0x20202020) {
116+
// buf += 4;
117+
// }
118+
//#endif
119+
// if (((uint16_t *)buf)[0] == 0x2020) {
120+
// buf += 2;
121+
// }
122+
// if (*buf == 0x20) {
123+
// ++buf;
124+
// }
125+
// if (*buf > 0x20) {
126+
// return buf;
127+
// }
128+
// break;
129+
//#if FLATCC_JSON_PARSE_WIDE_SPACE
130+
// }
131+
// if (((uint64_t *)buf)[1] != 0x2020202020202020) {
132+
// buf += 8;
133+
// goto descend;
134+
// }
135+
// buf += 16;
136+
//#endif
137+
// }
138+
//#endif
139139
#endif
140140
while (buf != end && *buf == 0x20) {
141141
++buf;

0 commit comments

Comments
 (0)