message: Intern file names in msg_location to make them cheaper to copy.
[pspp] / src / libpspp / intern.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010, 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef LIBPSPP_INTERN_H
18 #define LIBPSPP_INTERN_H 1
19
20 /* Interned strings.
21
22    An "interned" string is stored in a global hash table.  Only one copy of any
23    given string is kept in the hash table, which reduces memory usage in cases
24    where there might otherwise be many duplicates of a given string.
25
26    Interned strings can be compared for equality by comparing pointers, which
27    can also be a significant advantage in some cases.
28
29    Interned strings are immutable.
30
31    See http://en.wikipedia.org/wiki/String_interning for more information. */
32
33 #include <stdbool.h>
34 #include <stddef.h>
35
36 const char *intern_new (const char *);
37 const char *intern_new_if_nonnull (const char *);
38 const char *intern_ref (const char *);
39 const char *intern_ref_if_nonnull (const char *);
40 void intern_unref (const char *);
41
42 size_t intern_strlen (const char *);
43
44 bool is_interned_string (const char *);
45
46 #endif /* libpspp/intern.h */