Skip to content

Commit 01dc76b

Browse files
author
Owen Jones
committed
Add section on irep_idt and dstringt
1 parent 56256f1 commit 01dc76b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/util/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Folder util
55

6-
\author Martin Brain
6+
\author Martin Brain, Owen Jones
77

88
\section data_structures Data Structures
99

@@ -82,6 +82,19 @@ recurse on the expression on either side.
8282
[^2]: Unless `USE_STD_STRING` is set, this is actually
8383
a `dstring` and thus an integer which is a reference into a string table
8484

85+
\subsection irep_idt Irep_idt and Dstringt
86+
87+
Inside `irept`s, strings are stored as `irep_idt`s, or `irep_namet`s for
88+
keys to `named_sub` or `comments`. If `USE_STD_STRING` is set then both
89+
`irep_idt` and `irep_namet` are `typedef`ed to `std::string`, but by default
90+
it is not set and they are `typedef`ed to `dstringt`. `dstringt` has one
91+
field, an unsigned integer which is an index into a static table of strings.
92+
This makes it expensive to create a new string (because you have to look
93+
through the whole table to see if it is already there, and add it if it
94+
isn't) but very cheap to compare strings (just compare the two integers). It
95+
also means that when you have lots of copies of the same string you only have
96+
to store the whole string once, which saves space.
97+
8598
\dot
8699
digraph G {
87100
node [shape=box];

0 commit comments

Comments
 (0)