MCPcopy
hub / github.com/dropbox/godropbox / intern

Method intern

strings/intern.go:41–61  ·  view source on GitHub ↗
(s string, shouldCopy bool)

Source from the content-addressed store, hash-verified

39}
40
41func (p *InternStringPool) intern(s string, shouldCopy bool) string {
42 z, ok := p.get(s)
43 if ok {
44 return z
45 }
46
47 p.mutex.Lock()
48
49 z, ok = p.pool[s]
50 if !ok {
51 if shouldCopy {
52 s = string([]byte(s))
53 }
54 p.pool[s] = s
55 z = s
56 }
57
58 p.mutex.Unlock()
59
60 return z
61}
62
63func (p *InternStringPool) Intern(s string) string {
64 return p.intern(s, false)

Callers 2

InternMethod · 0.95
InternBytesMethod · 0.95

Calls 3

getMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected