diff options
author | Antti-Juhani Kaijanaho <ajk@debian.org> | 2012-06-09 00:36:26 +0300 |
---|---|---|
committer | Antti-Juhani Kaijanaho <ajk@debian.org> | 2012-06-09 00:36:26 +0300 |
commit | 541b6b9ec2dfbad0248b1e40fbc9b706b86decff (patch) | |
tree | 458193c5a18d8eda3ea0fa0ca185716d9cdbd985 | |
parent | 826bc801475ca264f036d97dc9e150a5c1490255 (diff) | |
download | dctrl-tools-541b6b9ec2dfbad0248b1e40fbc9b706b86decff.tar.gz |
lib/fsaf.[ch]: Make fsaf_read an inline function
Signed-off-by: Antti-Juhani Kaijanaho <ajk@debian.org>
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | lib/fsaf.c | 34 | ||||
-rw-r--r-- | lib/fsaf.h | 36 |
3 files changed, 39 insertions, 35 deletions
diff --git a/debian/changelog b/debian/changelog index 1e66f7c..68ecfe5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,8 +15,10 @@ dctrl-tools (2.23) UNRELEASED; urgency=low * tester.sh: Handle missing diffs gracefully. * lib/fsaf.c and others: Remove mmap support (recognize but ignore --mmap). It was only complicating matters without giving much benefit. + * lib/fsaf.[ch]: Make fsaf_read an inline function (50 % speedup in my + tests.) - -- Antti-Juhani Kaijanaho <ajk@debian.org> Sat, 09 Jun 2012 00:07:04 +0300 + -- Antti-Juhani Kaijanaho <ajk@debian.org> Sat, 09 Jun 2012 00:20:02 +0300 dctrl-tools (2.22.2) unstable; urgency=low @@ -82,7 +82,7 @@ static void slide(FSAF *fp) fp->buf_size -= delta; } -static void slurp(FSAF * fp, size_t len) +void fsaf_slurp(FSAF * fp, size_t len) { assert(fp != 0); assert(len > 0); @@ -121,38 +121,6 @@ static void slurp(FSAF * fp, size_t len) fp->buf_size += res; } -//static inline -struct fsaf_read_rv fsaf_read(FSAF * fp, size_t offset, size_t len) -{ - struct fsaf_read_rv rv; - - /* Reading nothing - since offset can be bogus in this - * situation, this could foul up our assumptions later, so - * return already here. */ - if (len == 0) { - rv.b = ""; - rv.len = 0; - return rv; - } - - /* Make sure we don't read past the EOF mark. */ - if (offset + len > fp->eof_mark) len = fp->eof_mark - offset; - - /* Ensure that we have enough data in the buffer. */ - assert(offset >= fp->buf_offset); - if (offset - fp->buf_offset + len > fp->buf_size) { - slurp(fp, offset - fp->buf_offset + len - fp->buf_size); - if (offset - fp->buf_offset + len > fp->buf_size) { - len = fp->buf_size - (offset - fp->buf_offset); - } - } - - assert(offset - fp->buf_offset + len <= fp->buf_size); - assert(offset + len <= fp->eof_mark); - rv.b = fp->buf + (offset - fp->buf_offset); - rv.len = len; - return rv; -} void fsaf_invalidate(FSAF * fp, size_t offset) { @@ -54,7 +54,41 @@ void fsaf_close(FSAF *); struct fsaf_read_rv { char const * b; size_t len; -} fsaf_read(FSAF *, size_t offset, size_t len); +}; +static inline +struct fsaf_read_rv fsaf_read(FSAF * fp, size_t offset, size_t len) +{ + struct fsaf_read_rv rv; + + void fsaf_slurp(FSAF * fp, size_t len); + + /* Reading nothing - since offset can be bogus in this + * situation, this could foul up our assumptions later, so + * return already here. */ + if (len == 0) { + rv.b = ""; + rv.len = 0; + return rv; + } + + /* Make sure we don't read past the EOF mark. */ + if (offset + len > fp->eof_mark) len = fp->eof_mark - offset; + + /* Ensure that we have enough data in the buffer. */ + assert(offset >= fp->buf_offset); + if (offset - fp->buf_offset + len > fp->buf_size) { + fsaf_slurp(fp, offset - fp->buf_offset + len - fp->buf_size); + if (offset - fp->buf_offset + len > fp->buf_size) { + len = fp->buf_size - (offset - fp->buf_offset); + } + } + + assert(offset - fp->buf_offset + len <= fp->buf_size); + assert(offset + len <= fp->eof_mark); + rv.b = fp->buf + (offset - fp->buf_offset); + rv.len = len; + return rv; +} /* Behaves like fsaf_read except that the result is put in a malloc'd * zero-terminated buffer. NULL return value indicates either memory |