File: string_pool.go

package info (click to toggle)
lazygit 0.50.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,808 kB
  • sloc: sh: 128; makefile: 76
file content (14 lines) | stat: -rw-r--r-- 319 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package utils

import "sync"

// A simple string pool implementation that can help reduce memory usage for
// cases where the same string is used multiple times.
type StringPool struct {
	sync.Map
}

func (self *StringPool) Add(s string) *string {
	poolEntry, _ := self.LoadOrStore(s, &s)
	return poolEntry.(*string)
}