mirror of
https://github.com/git/git.git
synced 2024-11-05 00:37:55 +01:00
1d73b52f5b
Intern strings so they can be compared by address and stored without wasting space. This library uses the macros in the obj_pool.h and trp.h to create a memory pool for strings and expose an API for handling them. [rr: added API docs] [jn: with some API simplifications, new documentation and tests] Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
31 lines
654 B
C
31 lines
654 B
C
/*
|
|
* test-string-pool.c: code to exercise the svn importer's string pool
|
|
*/
|
|
|
|
#include "git-compat-util.h"
|
|
#include "vcs-svn/string_pool.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
const uint32_t unequal = pool_intern("does not equal");
|
|
const uint32_t equal = pool_intern("equals");
|
|
uint32_t buf[3];
|
|
uint32_t n;
|
|
|
|
if (argc != 2)
|
|
usage("test-string-pool <string>,<string>");
|
|
|
|
n = pool_tok_seq(3, buf, ",-", argv[1]);
|
|
if (n >= 3)
|
|
die("too many strings");
|
|
if (n <= 1)
|
|
die("too few strings");
|
|
|
|
buf[2] = buf[1];
|
|
buf[1] = (buf[0] == buf[2]) ? equal : unequal;
|
|
pool_print_seq(3, buf, ' ', stdout);
|
|
fputc('\n', stdout);
|
|
|
|
pool_reset();
|
|
return 0;
|
|
}
|