github.com/vedadiyan/sqlparser@v1.0.0/pkg/hack/compat.go (about)

     1  //go:build !gc || wasm
     2  
     3  /*
     4  Copyright 2021 The Vitess Authors.
     5  
     6  Licensed under the Apache License, Version 2.0 (the "License");
     7  you may not use this file except in compliance with the License.
     8  You may obtain a copy of the License at
     9  
    10      http://www.apache.org/licenses/LICENSE-2.0
    11  
    12  Unless required by applicable law or agreed to in writing, software
    13  distributed under the License is distributed on an "AS IS" BASIS,
    14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  See the License for the specific language governing permissions and
    16  limitations under the License.
    17  */
    18  
    19  package hack
    20  
    21  // String returns b as a string. This compat function allocates memory.
    22  func String(b []byte) (s string) {
    23  	return string(b)
    24  }
    25  
    26  // StringBytes returns as a []byte. This compat function allocates memory.
    27  func StringBytes(s string) []byte {
    28  	return []byte(s)
    29  }
    30  
    31  // RuntimeMemhash is a slow hash function for bytes, implemented for compatibility.
    32  func RuntimeMemhash(b []byte, hash uint64) uint64 {
    33  	for i := 0; i < len(b); i++ {
    34  		hash *= 1099511628211
    35  		hash ^= uint64(b[i])
    36  	}
    37  	return hash
    38  }
    39  
    40  // RuntimeStrhash is a slow hash function for bytes, implemented for compatibility.
    41  func RuntimeStrhash(str string, hash uint64) uint64 {
    42  	for i := 0; i < len(str); i++ {
    43  		hash *= 1099511628211
    44  		hash ^= uint64(str[i])
    45  	}
    46  	return hash
    47  }
    48  
    49  // ParseFloatPrefix exposes the internal strconv method from the standard library
    50  //
    51  //go:linkname ParseFloatPrefix strconv.parseFloatPrefix
    52  func ParseFloatPrefix(s string, bitSize int) (float64, int, error)
    53  
    54  // RuntimeAllocSize is a no-op when Vitess is not compiled with GC
    55  func RuntimeAllocSize(size int64) int64 {
    56  	return size
    57  }