From 5008f5c5f26e410c921d7a0418490d70447725ef Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 29 Dec 2006 15:43:55 +0000 Subject: [PATCH] * lex.c (_cpp_clean_line): Add uses of __builtin_expect. Don't look backward at the end of the line unless we saw a backslash. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120263 138bc75d-0d04-0410-961f-82ee72b054a4 --- libcpp/ChangeLog | 5 +++++ libcpp/lex.c | 30 +++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index de8eb92095c..96c5140e707 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2006-12-29 Ian Lance Taylor + + * lex.c (_cpp_clean_line): Add uses of __builtin_expect. Don't + look backward at the end of the line unless we saw a backslash. + 2006-12-29 Jakub Jelinek PR preprocessor/29612 diff --git a/libcpp/lex.c b/libcpp/lex.c index df09bd6d3d6..5d1a688af9a 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -111,31 +111,39 @@ _cpp_clean_line (cpp_reader *pfile) if (!buffer->from_stage3) { + const uchar *pbackslash = NULL; + /* Short circuit for the common case of an un-escaped line with no trigraphs. The primary win here is by not writing any data back to memory until we have to. */ for (;;) { c = *++s; - if (c == '\n' || c == '\r') + if (__builtin_expect (c == '\n', false) + || __builtin_expect (c == '\r', false)) { d = (uchar *) s; - if (s == buffer->rlimit) + if (__builtin_expect (s == buffer->rlimit, false)) goto done; /* DOS line ending? */ - if (c == '\r' && s[1] == '\n') - s++; + if (__builtin_expect (c == '\r', false) + && s[1] == '\n') + { + s++; + if (s == buffer->rlimit) + goto done; + } - if (s == buffer->rlimit) + if (__builtin_expect (pbackslash == NULL, true)) goto done; - /* check for escaped newline */ + /* Check for escaped newline. */ p = d; - while (p != buffer->next_line && is_nvspace (p[-1])) + while (is_nvspace (p[-1])) p--; - if (p == buffer->next_line || p[-1] != '\\') + if (p - 1 != pbackslash) goto done; /* Have an escaped newline; process it and proceed to @@ -145,7 +153,11 @@ _cpp_clean_line (cpp_reader *pfile) buffer->next_line = p - 1; break; } - if (c == '?' && s[1] == '?' && _cpp_trigraph_map[s[2]]) + if (__builtin_expect (c == '\\', false)) + pbackslash = s; + else if (__builtin_expect (c == '?', false) + && __builtin_expect (s[1] == '?', false) + && _cpp_trigraph_map[s[2]]) { /* Have a trigraph. We may or may not have to convert it. Add a line note regardless, for -Wtrigraphs. */ -- 2.11.4.GIT