File: c_string_cache.go

package info (click to toggle)
golang-github-pzhin-go-sophia 0.0~git20250609.a1b0f01-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: ansic: 23,001; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 352 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package sophia

import (
	"sync"

	"C"
)

var cache = map[string]*C.char{}
var mLock sync.RWMutex

func getCStringFromCache(str string) *C.char {
	mLock.RLock()
	cStr, ok := cache[str]
	mLock.RUnlock()
	if ok {
		return cStr
	}

	mLock.Lock()
	cStr, ok = cache[str]
	if !ok {
		cStr = cString(str)
		cache[str] = cStr
	}
	mLock.Unlock()
	return cStr
}