Skip to content

Commit f6f4790

Browse files
committed
unlikely
1 parent b9c89fe commit f6f4790

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

simplecpp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
# include <sys/stat.h>
5959
#endif
6060

61+
#ifdef __GNUC__
62+
# define unlikely(x) __builtin_expect(!!(x), 0)
63+
#else
64+
# define unlikely(x) (x)
65+
#endif
66+
6167
static bool isHex(const std::string &s)
6268
{
6369
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
@@ -505,14 +511,14 @@ class FileStreamBuffered : public simplecpp::TokenList::Stream {
505511
private:
506512
void read_internal() {
507513
// check if we are in the last chunk
508-
if (buf_idx >= buf_len) {
514+
if (unlikely(buf_idx >= buf_len)) {
509515
if (buf_len != sizeof(buf)) {
510516
lastStatus = EOF;
511517
return;
512518
}
513519
}
514520

515-
if (buf_idx == -1 || buf_idx == buf_len)
521+
if (unlikely(buf_idx == -1 || buf_idx == buf_len))
516522
{
517523
buf_idx = 0;
518524
buf_len = fread(buf, 1, sizeof(buf), file);

0 commit comments

Comments
 (0)