Line data Source code
1 : // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package intern 6 : 7 : import "sync" 8 : 9 : var pool = sync.Pool{ 10 2 : New: func() interface{} { 11 2 : return make(map[string]string) 12 2 : }, 13 : } 14 : 15 : // Bytes returns b converted to a string, interned. 16 2 : func Bytes(b []byte) string { 17 2 : m := pool.Get().(map[string]string) 18 2 : c, ok := m[string(b)] 19 2 : if ok { 20 2 : pool.Put(m) 21 2 : return c 22 2 : } 23 2 : s := string(b) 24 2 : m[s] = s 25 2 : pool.Put(m) 26 2 : return s 27 : }