diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-08-31 16:23:38 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-08-31 16:23:38 -0700 |
commit | aca35505db3706c87d391dd213e856f73edfd42c (patch) | |
tree | 80b2d3878ae3ff21db1b1c21b9eaa6fefc290550 /vcs-svn/obj_pool.h | |
parent | d7cc7c971f58091a2f2a15d2dca0fab0bd2ca310 (diff) | |
parent | cd9a7b57a7118672441f9e9670a9fbb42249cf67 (diff) | |
download | git-aca35505db3706c87d391dd213e856f73edfd42c.tar.gz git-aca35505db3706c87d391dd213e856f73edfd42c.tar.xz |
Merge branch 'jn/svn-fe'
* jn/svn-fe:
t/t9010-svn-fe.sh: add an +x bit to this test
t9010 (svn-fe): avoid symlinks in test
t9010 (svn-fe): use Unix-style path in URI
vcs-svn: Avoid %z in format string
vcs-svn: Rename dirent pool to build on Windows
compat: add strtok_r()
treap: style fix
vcs-svn: remove build artifacts on "make clean"
svn-fe manual: Clarify warning about deltas in dump files
Update svn-fe manual
SVN dump parser
Infrastructure to write revisions in fast-export format
Add stream helper library
Add string-specific memory pool
Add treap implementation
Add memory pool library
Introduce vcs-svn lib
Diffstat (limited to 'vcs-svn/obj_pool.h')
-rw-r--r-- | vcs-svn/obj_pool.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vcs-svn/obj_pool.h b/vcs-svn/obj_pool.h new file mode 100644 index 000000000..deb6eb813 --- /dev/null +++ b/vcs-svn/obj_pool.h @@ -0,0 +1,61 @@ +/* + * Licensed under a two-clause BSD-style license. + * See LICENSE for details. + */ + +#ifndef OBJ_POOL_H_ +#define OBJ_POOL_H_ + +#include "git-compat-util.h" + +#define MAYBE_UNUSED __attribute__((__unused__)) + +#define obj_pool_gen(pre, obj_t, initial_capacity) \ +static struct { \ + uint32_t committed; \ + uint32_t size; \ + uint32_t capacity; \ + obj_t *base; \ +} pre##_pool = {0, 0, 0, NULL}; \ +static MAYBE_UNUSED uint32_t pre##_alloc(uint32_t count) \ +{ \ + uint32_t offset; \ + if (pre##_pool.size + count > pre##_pool.capacity) { \ + while (pre##_pool.size + count > pre##_pool.capacity) \ + if (pre##_pool.capacity) \ + pre##_pool.capacity *= 2; \ + else \ + pre##_pool.capacity = initial_capacity; \ + pre##_pool.base = realloc(pre##_pool.base, \ + pre##_pool.capacity * sizeof(obj_t)); \ + } \ + offset = pre##_pool.size; \ + pre##_pool.size += count; \ + return offset; \ +} \ +static MAYBE_UNUSED void pre##_free(uint32_t count) \ +{ \ + pre##_pool.size -= count; \ +} \ +static MAYBE_UNUSED uint32_t pre##_offset(obj_t *obj) \ +{ \ + return obj == NULL ? ~0 : obj - pre##_pool.base; \ +} \ +static MAYBE_UNUSED obj_t *pre##_pointer(uint32_t offset) \ +{ \ + return offset >= pre##_pool.size ? NULL : &pre##_pool.base[offset]; \ +} \ +static MAYBE_UNUSED void pre##_commit(void) \ +{ \ + pre##_pool.committed = pre##_pool.size; \ +} \ +static MAYBE_UNUSED void pre##_reset(void) \ +{ \ + free(pre##_pool.base); \ + pre##_pool.base = NULL; \ + pre##_pool.size = 0; \ + pre##_pool.capacity = 0; \ + pre##_pool.committed = 0; \ +} + +#endif |