Clean redundant except: blocks in run_test_server.
[arvados.git] / services / datamanager / summary / canonical_string.go
1 /* Ensures that we only have one copy of each unique string. This is
2 /* not designed for concurrent access. */
3 package summary
4
5 // This code should probably be moved somewhere more universal.
6
7 type CanonicalString struct {
8         m map[string]string
9 }
10
11 func (cs *CanonicalString) Get(s string) (r string) {
12         if cs.m == nil {
13                 cs.m = make(map[string]string)
14         }
15         value, found := cs.m[s]
16         if found {
17                 return value
18         }
19
20         // s may be a substring of a much larger string.
21         // If we store s, it will prevent that larger string from getting
22         // garbage collected.
23         // If this is something you worry about you should change this code
24         // to make an explict copy of s using a byte array.
25         cs.m[s] = s
26         return s
27 }