summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2013-08-30 15:46:12 +0400
committerDmitriy Vyukov <dvyukov@google.com>2013-08-30 15:46:12 +0400
commit5c03c230954d1491c25b14690d2b6bb96452cfa1 (patch)
tree4d916a84cc854b172ce2088cd8968c13316d8568 /include
parent564f6b8ad1baba0e954929e1f3ac0bc0735982c3 (diff)
downloadgo-5c03c230954d1491c25b14690d2b6bb96452cfa1.tar.gz
libbio, all cmd: consistently use BGETC/BPUTC instead of Bgetc/Bputc
Also introduce BGET2/4, BPUT2/4 as they are widely used. Slightly improve BGETC/BPUTC implementation. This gives ~5% CPU time improvement on go install -a -p1 std. Before: real user sys 0m23.561s 0m16.625s 0m5.848s 0m23.766s 0m16.624s 0m5.846s 0m23.742s 0m16.621s 0m5.868s after: 0m22.999s 0m15.841s 0m5.889s 0m22.845s 0m15.808s 0m5.850s 0m22.889s 0m15.832s 0m5.848s R=golang-dev, r CC=golang-dev https://codereview.appspot.com/12745047
Diffstat (limited to 'include')
-rw-r--r--include/bio.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/include/bio.h b/include/bio.h
index c754d7a57..be4d8d80e 100644
--- a/include/bio.h
+++ b/include/bio.h
@@ -70,10 +70,28 @@ struct Biobuf
unsigned char b[Bungetsize+Bsize];
};
+/*
+ * These macros get 1-, 2-, and 4-byte integer values by reading the
+ * next few bytes in little-endian order.
+ */
#define BGETC(bp)\
- ((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp)))
+ ((bp)->icount?(bp)->ebuf[(bp)->icount++]:Bgetc((bp)))
+#define BGETLE2(bp)\
+ ((bp)->icount<=-2?((bp)->icount+=2,((bp)->ebuf[(bp)->icount-2])|((bp)->ebuf[(bp)->icount-1]<<8)):Bgetle2((bp)))
+#define BGETLE4(bp)\
+ ((bp)->icount<=-4?((bp)->icount+=4,((bp)->ebuf[(bp)->icount-4])|((bp)->ebuf[(bp)->icount-3]<<8)|((bp)->ebuf[(bp)->icount-2]<<16)|((bp)->ebuf[(bp)->icount-1]<<24)):Bgetle4((bp)))
+
+/*
+ * These macros put 1-, 2-, and 4-byte integer values by writing the
+ * next few bytes in little-endian order.
+ */
#define BPUTC(bp,c)\
- ((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c)))
+ ((bp)->ocount?(bp)->ebuf[(bp)->ocount++]=(unsigned char)(c),0:Bputc((bp),(c)))
+#define BPUTLE2(bp,c)\
+ ((bp)->ocount<=-2?(bp)->ocount+=2,(bp)->ebuf[(bp)->ocount-2]=(unsigned char)(c),(bp)->ebuf[(bp)->ocount-1]=(unsigned char)(c>>8),0:Bputle2((bp),(c)))
+#define BPUTLE4(bp,c)\
+ ((bp)->ocount<=-4?(bp)->ocount+=4,(bp)->ebuf[(bp)->ocount-4]=(unsigned char)(c),(bp)->ebuf[(bp)->ocount-3]=(unsigned char)(c>>8),(bp)->ebuf[(bp)->ocount-2]=(unsigned char)(c>>16),(bp)->ebuf[(bp)->ocount-1]=(unsigned char)(c>>24),0:Bputle4((bp),(c)))
+
#define BOFFSET(bp)\
(((bp)->state==Bractive)?\
(bp)->offset + (bp)->icount:\
@@ -90,6 +108,8 @@ Biobuf* Bfdopen(int, int);
int Bfildes(Biobuf*);
int Bflush(Biobuf*);
int Bgetc(Biobuf*);
+int Bgetle2(Biobuf*);
+int Bgetle4(Biobuf*);
int Bgetd(Biobuf*, double*);
long Bgetrune(Biobuf*);
int Binit(Biobuf*, int, int);
@@ -99,6 +119,8 @@ vlong Boffset(Biobuf*);
Biobuf* Bopen(char*, int);
int Bprint(Biobuf*, char*, ...);
int Bputc(Biobuf*, int);
+int Bputle2(Biobuf*, int);
+int Bputle4(Biobuf*, int);
int Bputrune(Biobuf*, long);
void* Brdline(Biobuf*, int);
char* Brdstr(Biobuf*, int, int);