factor analysis code out of codegen

This commit is contained in:
Josh Wolfe
2015-11-30 09:14:58 -07:00
parent 020f854f6f
commit 9e0ff6faa2
9 changed files with 643 additions and 595 deletions

View File

@@ -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;
}