summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti-Juhani Kaijanaho <ajk@debian.org>2012-06-09 00:36:26 +0300
committerAntti-Juhani Kaijanaho <ajk@debian.org>2012-06-09 00:36:26 +0300
commit541b6b9ec2dfbad0248b1e40fbc9b706b86decff (patch)
tree458193c5a18d8eda3ea0fa0ca185716d9cdbd985
parent826bc801475ca264f036d97dc9e150a5c1490255 (diff)
downloaddctrl-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/changelog4
-rw-r--r--lib/fsaf.c34
-rw-r--r--lib/fsaf.h36
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
diff --git a/lib/fsaf.c b/lib/fsaf.c
index c132dc9..eb2a009 100644
--- a/lib/fsaf.c
+++ b/lib/fsaf.c
@@ -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)
{
diff --git a/lib/fsaf.h b/lib/fsaf.h
index 6f5f91a..516d86a 100644
--- a/lib/fsaf.h
+++ b/lib/fsaf.h
@@ -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