aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-09 10:21:45 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:05:45 -0700
commitfd46a87b9e1d032863c41f54009e5e6386862f8b (patch)
treed9eb25525e6fa4f8fe4f0e7b9ed6a83c8572b23f /pre-process.c
parentMake "last_reg" be entry-point global rather than bb-global. (diff)
downloadsparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.tar.gz
sparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.tar.bz2
sparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.zip
Remove stat-based file identity tests.
Replace it with a simple pathname comparison instead. The pathname check is not only portable (no need for any compatibility helper functions), but we can do it much earlier, and thus make the check much cheaper by avoiding three extra system calls when it triggers (open/fstat/close). And the pathname test seems to match all the cases anyway.
Diffstat (limited to 'pre-process.c')
-rw-r--r--pre-process.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/pre-process.c b/pre-process.c
index 950aea3..0a24f56 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -596,6 +596,23 @@ static const char *token_name_sequence(struct token *token, int endop, struct to
return buffer;
}
+static int already_tokenized(const char *path)
+{
+ int i;
+ struct stream *s = input_streams;
+
+ for (i = input_stream_nr-1; i >= 0; i--, s++) {
+ if (s->constant != CONSTANT_FILE_YES)
+ continue;
+ if (strcmp(path, s->name))
+ continue;
+ if (!lookup_symbol(s->protect, NS_MACRO))
+ continue;
+ return 1;
+ }
+ return 0;
+}
+
static int try_include(const char *path, int plen, const char *filename, int flen, struct token **where, const char **next_path)
{
int fd;
@@ -607,6 +624,8 @@ static int try_include(const char *path, int plen, const char *filename, int fle
plen++;
}
memcpy(fullname+plen, filename, flen);
+ if (already_tokenized(fullname))
+ return 1;
fd = open(fullname, O_RDONLY);
if (fd >= 0) {
char * streamname = __alloc_bytes(plen + flen);