aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.cpp
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2015-11-30 09:14:58 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2015-11-30 09:14:58 -0700
commit9e0ff6faa2458a431875b38d24f754def450117e (patch)
tree1cc856285f34f880523f395fbaf7b9838a0fcb11 /src/buffer.cpp
parent020f854f6f794e8f9a39ad9d18c6173650ed5be3 (diff)
downloadzig-9e0ff6faa2458a431875b38d24f754def450117e.tar.gz
zig-9e0ff6faa2458a431875b38d24f754def450117e.zip
factor analysis code out of codegen
Diffstat (limited to 'src/buffer.cpp')
-rw-r--r--src/buffer.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/buffer.cpp b/src/buffer.cpp
index 6607bb389c..1978371034 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -45,3 +45,20 @@ void buf_appendf(Buf *buf, const char *format, ...) {
va_end(ap2);
va_end(ap);
}
+
+// these functions are not static inline so they can be better used as template parameters
+bool buf_eql_buf(Buf *buf, Buf *other) {
+ assert(buf->list.length);
+ return buf_eql_mem(buf, buf_ptr(other), buf_len(other));
+}
+
+uint32_t buf_hash(Buf *buf) {
+ assert(buf->list.length);
+ // FNV 32-bit hash
+ uint32_t h = 2166136261;
+ for (int i = 0; i < buf_len(buf); i += 1) {
+ h = h ^ ((uint8_t)buf->list.at(i));
+ h = h * 16777619;
+ }
+ return h;
+}