summaryrefslogtreecommitdiff
path: root/saa.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-10 09:29:20 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-10 09:29:20 -0700
commit1cff81e3562645b55fbe4beb7856c5ef8b7e910a (patch)
treeb3d91a57e8f655f3ee34885891c613b2cf5a6916 /saa.c
parent11627049aec88e21b6a9cbdef10984868d4ca3fe (diff)
downloadnasm-1cff81e3562645b55fbe4beb7856c5ef8b7e910a.tar.gz
nasm-1cff81e3562645b55fbe4beb7856c5ef8b7e910a.tar.bz2
nasm-1cff81e3562645b55fbe4beb7856c5ef8b7e910a.zip
SAA: optimize seeks when used on a byte array
In practice, we only ever use the seeking functions on byte arrays (elem_len == 1). Optimize for that case, to avoid a general divmod operation.
Diffstat (limited to 'saa.c')
-rw-r--r--saa.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/saa.c b/saa.c
index 340068a..046659e 100644
--- a/saa.c
+++ b/saa.c
@@ -3,7 +3,8 @@
#include "saa.h"
/* Aggregate SAA components smaller than this */
-#define SAA_BLKLEN 65536
+#define SAA_BLKSHIFT 16
+#define SAA_BLKLEN ((size_t)1 << SAA_BLKSHIFT)
struct SAA *saa_init(size_t elem_len)
{
@@ -210,9 +211,14 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
return;
}
- ix = posn / s->blk_len;
+ if (s->elem_len == 1) {
+ ix = posn >> SAA_BLKSHIFT;
+ s->rpos = posn & (SAA_BLKLEN-1);
+ } else {
+ ix = posn / s->blk_len;
+ s->rpos = posn % s->blk_len;
+ }
s->rptr = posn;
- s->rpos = posn % s->blk_len;
s->rblk = &s->blk_ptrs[ix];
saa_rnbytes(s, data, len);
@@ -229,9 +235,15 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
return;
}
- ix = posn / s->blk_len;
+
+ if (s->elem_len == 1) {
+ ix = posn >> SAA_BLKSHIFT;
+ s->wpos = posn & (SAA_BLKLEN-1);
+ } else {
+ ix = posn / s->blk_len;
+ s->wpos = posn % s->blk_len;
+ }
s->wptr = posn;
- s->wpos = posn % s->blk_len;
s->wblk = &s->blk_ptrs[ix];
if (!s->wpos) {