Skip to content

Commit 75bc73f

Browse files
committed
unlikely
1 parent 4b03baa commit 75bc73f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

simplecpp.cpp

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

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

516-
if (buf_idx == -1 || buf_idx == buf_len)
522+
if (unlikely(buf_idx == -1 || buf_idx == buf_len))
517523
{
518524
buf_idx = 0;
519525
buf_len = fread(buf, 1, sizeof(buf), file);

0 commit comments

Comments
 (0)