blob: 873c26a645a03313332d1c5a6e2765236083cdee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// stringpool.h -- a string pool for gold -*- C++ -*-
#include <string>
#include <list>
// Stringpool
// Manage a pool of unique strings.
#ifndef GOLD_STRINGPOOL_H
#define GOLD_STRINGPOOL_H
namespace gold
{
class Stringpool
{
public:
Stringpool();
~Stringpool();
// Add a string to the pool. This returns a canonical permanent
// pointer to the string.
const char* add(const char*);
const char* add(const std::string& s)
{ return this->add(s.c_str()); }
// Add the prefix of a string to the pool.
const char* add(const char *, size_t);
private:
Stringpool(const Stringpool&);
Stringpool& operator=(const Stringpool&);
struct stringdata
{
// Length of data in buffer.
size_t len;
// Allocated size of buffer.
size_t alc;
// Buffer.
char data[1];
};
const char* add_string(const char*);
struct Stringpool_hash
{
size_t
operator()(const char*) const;
};
struct Stringpool_eq
{
bool
operator()(const char* p1, const char* p2) const
{ return strcmp(p1, p2) == 0; }
};
typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
std::allocator<const char*>,
true> String_set_type;
String_set_type string_set_;
std::list<stringdata*> strings_;
};
} // End namespace gold.
#endif // !defined(GOLD_STRINGPOOL_H)
|