@@ -269,28 +269,33 @@ const char* etf_parser::read_string(uint32_t length) {
269
269
return (const char *)str;
270
270
}
271
271
272
- static const char * atom_null = " null" ;
273
- static const char * atom_true = " true" ;
274
- static const char * atom_false = " false" ;
275
-
276
272
json etf_parser::process_atom (const char * atom, uint16_t length) {
277
273
json j;
278
274
279
275
if (atom == NULL ) {
280
276
return j;
281
277
}
282
278
279
+ /* *
280
+ * WARNING: PERFORMANCE HOTSPOT
281
+ * Valgrind cachegrind identified this as a performance hotspot in DPP when using ETF. This gets called a LOT,
282
+ * and the difference here between comparing the simple constant types here where the lengths are known in this
283
+ * way, compared to using memcpy or strncpy four times, is absolutely huge (factors of ten). Considering this
284
+ * can be called hundreds of times a second on a busy bot, the performance of this function should not be
285
+ * underestimated. Think carefully before 'tidying' this function further!
286
+ *
287
+ */
283
288
if (length >= 3 && length <= 5 ) {
284
- if (length == 4 && *(( uint32_t *) atom) == *(( uint32_t *)atom_null) ) { // "null"
289
+ if (length == 4 && atom[ 0 ] == ' n ' && atom[ 1 ] == ' u ' && atom[ 2 ] == ' l ' && atom[ 3 ] == ' l ' ) { // "null"
285
290
return j;
286
291
}
287
- else if (length == 4 && *(( uint32_t *) atom) == *(( uint32_t *)atom_true) ) { // "true"
292
+ else if (length == 4 && atom[ 0 ] == ' t ' && atom[ 1 ] == ' r ' && atom[ 2 ] == ' u ' && atom[ 3 ] == ' e ' ) { // "true"
288
293
return true ;
289
294
}
290
295
else if (length == 3 && atom[0 ] == ' n' && atom[1 ] == ' i' && atom[2 ] == ' l' ) { // "nil"
291
296
return j;
292
297
}
293
- else if (length == 5 && *(( uint32_t *) atom) == *(( uint32_t *)atom_false) && atom[4 ] == ' e' ) { // "fals","e"
298
+ else if (length == 5 && atom[ 0 ] == ' f ' && atom[ 1 ] == ' a ' && atom[ 2 ] == ' l ' && atom[ 3 ] == ' s ' && atom[4 ] == ' e' ) { // "fals","e"
294
299
return false ;
295
300
}
296
301
}
0 commit comments