diff options
| author | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-11-30 09:14:58 -0700 |
|---|---|---|
| committer | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-11-30 09:14:58 -0700 |
| commit | 9e0ff6faa2458a431875b38d24f754def450117e (patch) | |
| tree | 1cc856285f34f880523f395fbaf7b9838a0fcb11 /src/buffer.cpp | |
| parent | 020f854f6f794e8f9a39ad9d18c6173650ed5be3 (diff) | |
| download | zig-9e0ff6faa2458a431875b38d24f754def450117e.tar.gz zig-9e0ff6faa2458a431875b38d24f754def450117e.zip | |
factor analysis code out of codegen
Diffstat (limited to 'src/buffer.cpp')
| -rw-r--r-- | src/buffer.cpp | 17 |
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; +} |
