github.com/dgraph-io/simdjson-go@v0.3.0/parse_string_amd64.go (about)

     1  //+build !noasm
     2  //+build !appengine
     3  //+build gc
     4  
     5  /*
     6   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     7   *
     8   * Licensed under the Apache License, Version 2.0 (the "License");
     9   * you may not use this file except in compliance with the License.
    10   * You may obtain a copy of the License at
    11   *
    12   *     http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an "AS IS" BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   */
    20  
    21  package simdjson
    22  
    23  import (
    24  	"reflect"
    25  	"unsafe"
    26  )
    27  
    28  //go:noescape
    29  func _parse_string_validate_only(src, maxStringSize, str_length, dst_length unsafe.Pointer) (result uint64)
    30  
    31  //go:noescape
    32  func _parse_string(src, dst, pcurrent_string_buf_loc unsafe.Pointer) (res uint64)
    33  
    34  // Disable new -d=checkptr behaviour for Go 1.14
    35  //go:nocheckptr
    36  func parseStringSimdValidateOnly(buf []byte, maxStringSize, dst_length *uint64, need_copy *bool) bool {
    37  
    38  	src := uintptr(unsafe.Pointer(&buf[1])) // Use buf[1] in order to skip opening quote
    39  	src_length := uint64(0)
    40  
    41  	success := _parse_string_validate_only(unsafe.Pointer(src), unsafe.Pointer(&maxStringSize), unsafe.Pointer(&src_length), unsafe.Pointer(dst_length))
    42  
    43  	*need_copy = alwaysCopyStrings || src_length != *dst_length
    44  	return success != 0
    45  }
    46  
    47  // Disable new -d=checkptr behaviour for Go 1.14
    48  //go:nocheckptr
    49  func parseStringSimd(buf []byte, stringbuf *[]byte) bool {
    50  
    51  	sh := (*reflect.SliceHeader)(unsafe.Pointer(stringbuf))
    52  
    53  	src := uintptr(unsafe.Pointer(&buf[1])) // Use buf[1] in order to skip opening quote
    54  	string_buf_loc := uintptr(unsafe.Pointer(sh.Data)) + uintptr(sh.Len)
    55  	dst := string_buf_loc
    56  
    57  	res := _parse_string(unsafe.Pointer(src), unsafe.Pointer(dst), unsafe.Pointer(&string_buf_loc))
    58  
    59  	sh.Len += int(uintptr(string_buf_loc) - dst)
    60  
    61  	return res != 0
    62  }