@matheusbsbs / matheus-bagliano / commits / cba3546a43
Fork 0

vcs-svn: drop obj_pool

This reverts commit 4709455db3891f6cad9a96a574296b4926f70cbe (Add memory pool library, 2010-08-09). svn-fe uses strbufs to avoid memory allocation overhead nowadays. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

David Barr committed Dec 13, 2010 at 21:26 UTC cba3546a43c64e2078664dbb6469aadf6bc473d3
5 files changed +1 -260
.gitignore
-1
@@ -171,7 +171,6 @@
171 /test-line-buffer
172 /test-match-trees
173 /test-mktemp
174 -/test-obj-pool
174 /test-parse-options
175 /test-path-utils
176 /test-run-command
Makefile
+1 -3
@@ -424,7 +424,6 @@ TEST_PROGRAMS_NEED_X += test-dump-cache-tree
424 TEST_PROGRAMS_NEED_X += test-genrandom
425 TEST_PROGRAMS_NEED_X += test-line-buffer
426 TEST_PROGRAMS_NEED_X += test-match-trees
427 -TEST_PROGRAMS_NEED_X += test-obj-pool
427 TEST_PROGRAMS_NEED_X += test-parse-options
428 TEST_PROGRAMS_NEED_X += test-path-utils
429 TEST_PROGRAMS_NEED_X += test-run-command
@@ -1838,7 +1837,7 @@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
1837 xdiff/xmerge.o xdiff/xpatience.o
1838 VCSSVN_OBJS = vcs-svn/line_buffer.o vcs-svn/repo_tree.o \
1839 vcs-svn/fast_export.o vcs-svn/svndump.o
1841 -VCSSVN_TEST_OBJS = test-obj-pool.o test-line-buffer.o
1840 +VCSSVN_TEST_OBJS = test-line-buffer.o
1841 OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS)
1842
1843 dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1962,7 +1961,6 @@ xdiff-interface.o $(XDIFF_OBJS): \
1961 xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
1962
1963 $(VCSSVN_OBJS) $(VCSSVN_TEST_OBJS): $(LIB_H) \
1965 - vcs-svn/obj_pool.h \
1964 vcs-svn/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \
1965 vcs-svn/svndump.h
1966
t/t0080-vcs-svn.sh deleted
-79
@@ -1,79 +0,0 @@
1 -#!/bin/sh
2 -
3 -test_description='check infrastructure for svn importer'
4 -
5 -. ./test-lib.sh
6 -uint32_max=4294967295
7 -
8 -test_expect_success 'obj pool: store data' '
9 - cat <<-\EOF >expected &&
10 - 0
11 - 1
12 - EOF
13 -
14 - test-obj-pool <<-\EOF >actual &&
15 - alloc one 16
16 - set one 13
17 - test one 13
18 - reset one
19 - EOF
20 - test_cmp expected actual
21 -'
22 -
23 -test_expect_success 'obj pool: NULL is offset ~0' '
24 - echo "$uint32_max" >expected &&
25 - echo null one | test-obj-pool >actual &&
26 - test_cmp expected actual
27 -'
28 -
29 -test_expect_success 'obj pool: out-of-bounds access' '
30 - cat <<-EOF >expected &&
31 - 0
32 - 0
33 - $uint32_max
34 - $uint32_max
35 - 16
36 - 20
37 - $uint32_max
38 - EOF
39 -
40 - test-obj-pool <<-\EOF >actual &&
41 - alloc one 16
42 - alloc two 16
43 - offset one 20
44 - offset two 20
45 - alloc one 5
46 - offset one 20
47 - free one 1
48 - offset one 20
49 - reset one
50 - reset two
51 - EOF
52 - test_cmp expected actual
53 -'
54 -
55 -test_expect_success 'obj pool: high-water mark' '
56 - cat <<-\EOF >expected &&
57 - 0
58 - 0
59 - 10
60 - 20
61 - 20
62 - 20
63 - EOF
64 -
65 - test-obj-pool <<-\EOF >actual &&
66 - alloc one 10
67 - committed one
68 - alloc one 10
69 - commit one
70 - committed one
71 - alloc one 10
72 - free one 20
73 - committed one
74 - reset one
75 - EOF
76 - test_cmp expected actual
77 -'
78 -
79 -test_done
test-obj-pool.c deleted
-116
@@ -1,116 +0,0 @@
1 -/*
2 - * test-obj-pool.c: code to exercise the svn importer's object pool
3 - */
4 -
5 -#include "cache.h"
6 -#include "vcs-svn/obj_pool.h"
7 -
8 -enum pool { POOL_ONE, POOL_TWO };
9 -obj_pool_gen(one, int, 1)
10 -obj_pool_gen(two, int, 4096)
11 -
12 -static uint32_t strtouint32(const char *s)
13 -{
14 - char *end;
15 - uintmax_t n = strtoumax(s, &end, 10);
16 - if (*s == '\0' || (*end != '\n' && *end != '\0'))
17 - die("invalid offset: %s", s);
18 - return (uint32_t) n;
19 -}
20 -
21 -static void handle_command(const char *command, enum pool pool, const char *arg)
22 -{
23 - switch (*command) {
24 - case 'a':
25 - if (!prefixcmp(command, "alloc ")) {
26 - uint32_t n = strtouint32(arg);
27 - printf("%"PRIu32"\n",
28 - pool == POOL_ONE ?
29 - one_alloc(n) : two_alloc(n));
30 - return;
31 - }
32 - case 'c':
33 - if (!prefixcmp(command, "commit ")) {
34 - pool == POOL_ONE ? one_commit() : two_commit();
35 - return;
36 - }
37 - if (!prefixcmp(command, "committed ")) {
38 - printf("%"PRIu32"\n",
39 - pool == POOL_ONE ?
40 - one_pool.committed : two_pool.committed);
41 - return;
42 - }
43 - case 'f':
44 - if (!prefixcmp(command, "free ")) {
45 - uint32_t n = strtouint32(arg);
46 - pool == POOL_ONE ? one_free(n) : two_free(n);
47 - return;
48 - }
49 - case 'n':
50 - if (!prefixcmp(command, "null ")) {
51 - printf("%"PRIu32"\n",
52 - pool == POOL_ONE ?
53 - one_offset(NULL) : two_offset(NULL));
54 - return;
55 - }
56 - case 'o':
57 - if (!prefixcmp(command, "offset ")) {
58 - uint32_t n = strtouint32(arg);
59 - printf("%"PRIu32"\n",
60 - pool == POOL_ONE ?
61 - one_offset(one_pointer(n)) :
62 - two_offset(two_pointer(n)));
63 - return;
64 - }
65 - case 'r':
66 - if (!prefixcmp(command, "reset ")) {
67 - pool == POOL_ONE ? one_reset() : two_reset();
68 - return;
69 - }
70 - case 's':
71 - if (!prefixcmp(command, "set ")) {
72 - uint32_t n = strtouint32(arg);
73 - if (pool == POOL_ONE)
74 - *one_pointer(n) = 1;
75 - else
76 - *two_pointer(n) = 1;
77 - return;
78 - }
79 - case 't':
80 - if (!prefixcmp(command, "test ")) {
81 - uint32_t n = strtouint32(arg);
82 - printf("%d\n", pool == POOL_ONE ?
83 - *one_pointer(n) : *two_pointer(n));
84 - return;
85 - }
86 - default:
87 - die("unrecognized command: %s", command);
88 - }
89 -}
90 -
91 -static void handle_line(const char *line)
92 -{
93 - const char *arg = strchr(line, ' ');
94 - enum pool pool;
95 -
96 - if (arg && !prefixcmp(arg + 1, "one"))
97 - pool = POOL_ONE;
98 - else if (arg && !prefixcmp(arg + 1, "two"))
99 - pool = POOL_TWO;
100 - else
101 - die("no pool specified: %s", line);
102 -
103 - handle_command(line, pool, arg + strlen("one "));
104 -}
105 -
106 -int main(int argc, char *argv[])
107 -{
108 - struct strbuf sb = STRBUF_INIT;
109 - if (argc != 1)
110 - usage("test-obj-str < script");
111 -
112 - while (strbuf_getline(&sb, stdin, '\n') != EOF)
113 - handle_line(sb.buf);
114 - strbuf_release(&sb);
115 - return 0;
116 -}
vcs-svn/obj_pool.h deleted
-61
@@ -1,61 +0,0 @@
1 -/*
2 - * Licensed under a two-clause BSD-style license.
3 - * See LICENSE for details.
4 - */
5 -
6 -#ifndef OBJ_POOL_H_
7 -#define OBJ_POOL_H_
8 -
9 -#include "git-compat-util.h"
10 -
11 -#define MAYBE_UNUSED __attribute__((__unused__))
12 -
13 -#define obj_pool_gen(pre, obj_t, initial_capacity) \
14 -static struct { \
15 - uint32_t committed; \
16 - uint32_t size; \
17 - uint32_t capacity; \
18 - obj_t *base; \
19 -} pre##_pool = {0, 0, 0, NULL}; \
20 -static MAYBE_UNUSED uint32_t pre##_alloc(uint32_t count) \
21 -{ \
22 - uint32_t offset; \
23 - if (pre##_pool.size + count > pre##_pool.capacity) { \
24 - while (pre##_pool.size + count > pre##_pool.capacity) \
25 - if (pre##_pool.capacity) \
26 - pre##_pool.capacity *= 2; \
27 - else \
28 - pre##_pool.capacity = initial_capacity; \
29 - pre##_pool.base = realloc(pre##_pool.base, \
30 - pre##_pool.capacity * sizeof(obj_t)); \
31 - } \
32 - offset = pre##_pool.size; \
33 - pre##_pool.size += count; \
34 - return offset; \
35 -} \
36 -static MAYBE_UNUSED void pre##_free(uint32_t count) \
37 -{ \
38 - pre##_pool.size -= count; \
39 -} \
40 -static MAYBE_UNUSED uint32_t pre##_offset(obj_t *obj) \
41 -{ \
42 - return obj == NULL ? ~0 : obj - pre##_pool.base; \
43 -} \
44 -static MAYBE_UNUSED obj_t *pre##_pointer(uint32_t offset) \
45 -{ \
46 - return offset >= pre##_pool.size ? NULL : &pre##_pool.base[offset]; \
47 -} \
48 -static MAYBE_UNUSED void pre##_commit(void) \
49 -{ \
50 - pre##_pool.committed = pre##_pool.size; \
51 -} \
52 -static MAYBE_UNUSED void pre##_reset(void) \
53 -{ \
54 - free(pre##_pool.base); \
55 - pre##_pool.base = NULL; \
56 - pre##_pool.size = 0; \
57 - pre##_pool.capacity = 0; \
58 - pre##_pool.committed = 0; \
59 -}
60 -
61 -#endif