diff options
author | pfg <pfg@FreeBSD.org> | 2013-11-16 01:07:02 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2013-11-16 01:07:02 +0000 |
commit | d27f7c2a842e4f80ea9a2408d941730107efd355 (patch) | |
tree | aeaba23e8862c5a47c20ef7eff077d79a61647c2 /contrib/gcclibs/libcpp/lex.c | |
parent | 43666eab78b10808646ed428d2019b2dcf0d92f0 (diff) | |
download | FreeBSD-src-d27f7c2a842e4f80ea9a2408d941730107efd355.zip FreeBSD-src-d27f7c2a842e4f80ea9a2408d941730107efd355.tar.gz |
libcpp: preprocessor speedup patches from mainline.
* 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.
* internal.h (struct cpp_reader): Add new fields:
nonexistent_file_hash and nonexistent_file_ob.
* files.c: Include "obstack.h".
(find_file_in_dir): Before trying to open the file, look up the
path name in the hash table of nonexistent files. After failing
to open the file, add the path name to the hash table.
(_cpp_find_file): Cache the results of looking up the file name
starting with the quote and bracket chain heads, if we can.
(nonexistent_file_hash_eq): New static function.
(_cpp_init_files): Initialize pfile->nonexistent_file_hash and
pfile->nonexistent_file_ob.
(_cpp_cleanup_files): Free pfile->nonexistent_file_hash and
pfile->nonexistent_file_ob.
Obtained from: gcc 4.3 (rev. 120263, 124929 ; GPLv2)
MFC after: 3 weeks
Diffstat (limited to 'contrib/gcclibs/libcpp/lex.c')
-rw-r--r-- | contrib/gcclibs/libcpp/lex.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/contrib/gcclibs/libcpp/lex.c b/contrib/gcclibs/libcpp/lex.c index df09bd6..5d1a688 100644 --- a/contrib/gcclibs/libcpp/lex.c +++ b/contrib/gcclibs/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. */ |