github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/intern/intern.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package intern lets you make smaller comparable values by boxing
     6  // a larger comparable value (such as a 16 byte string header) down
     7  // into a globally unique 8 byte pointer.
     8  //
     9  // The globally unique pointers are garbage collected with weak
    10  // references and finalizers. This package hides that.
    11  package intern
    12  
    13  // A Value pointer is the handle to an underlying comparable value.
    14  // See func Get for how Value pointers may be used.
    15  type Value struct {
    16  	_      [0]func()
    17  	cmpVal any
    18  	// resurrected is guarded by mu (for all instances of Value).
    19  	// It is set true whenever v is synthesized from a uintptr.
    20  	resurrected bool
    21  }
    22  
    23  // Get returns the comparable value passed to the Get func
    24  // that returned v.
    25  func (v *Value) Get() any
    26  
    27  // Get returns a pointer representing the comparable value cmpVal.
    28  //
    29  // The returned pointer will be the same for Get(v) and Get(v2)
    30  // if and only if v == v2, and can be used as a map key.
    31  func Get(cmpVal any) *Value
    32  
    33  // GetByString is identical to Get, except that it is specialized for strings.
    34  // This avoids an allocation from putting a string into an interface{}
    35  // to pass as an argument to Get.
    36  func GetByString(s string) *Value