Skip to content

Commit 92ebd48

Browse files
committed
Don't mess up underscore, make it 14% faster
1 parent da62fb6 commit 92ebd48

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

libEpollBenchmarker/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ override CFLAGS += -DUWS_NO_ZLIB -I../src -I../uSockets/src
66

77
default:
88
make -C ../uSockets
9-
g++ -flto -O3 -std=c++17 ../examples/HelloWorld.cpp epoll_benchmarker.cpp $(CFLAGS) -o HelloWorld ../uSockets/uSockets.a
9+
$(CXX) -flto -O3 -std=c++17 ../examples/HelloWorld.cpp epoll_benchmarker.cpp $(CFLAGS) -o HelloWorld ../uSockets/uSockets.a

src/HttpParser.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,24 @@ struct HttpParser {
247247
hasBetween(x, 'Z', 'a') |
248248
hasMore(x, 'z');
249249
}
250+
251+
static inline bool isFieldNameByteFastLowercased(unsigned char &in) {
252+
if ((in >= 97 & in <= 122) | (in == '-')) [[likely]] {
253+
return true;
254+
} else if (in >= 65 & in <= 90) [[unlikely]] {
255+
in |= 32;
256+
return true;
257+
} else if (isFieldNameByte(in)) [[unlikely]] {
258+
return true;
259+
}
260+
return false;
261+
}
250262

251263
static inline void *consumeFieldName(char *p) {
252-
//for (; true; p += 8) {
253-
//uint64_t word;
254-
//memcpy(&word, p, sizeof(uint64_t));
255-
//if (notFieldNameWord(word)) {
256-
while (isFieldNameByte(*(unsigned char *)p)) {
257-
*(p++) |= 0x20;
258-
}
259-
return (void *)p;
260-
//}
261-
//word |= 0x2020202020202020ull;
262-
//memcpy(p, &word, sizeof(uint64_t));
263-
//}
264+
while (isFieldNameByteFastLowercased(*(unsigned char *)p)) {
265+
p++;
266+
}
267+
return (void *)p;
264268
}
265269

266270
/* Puts method as key, target as value and returns non-null (or nullptr on error). */

0 commit comments

Comments
 (0)