github.com/minio/simdjson-go@v0.4.6-0.20231116094823-04d21cddf993/parse_string_amd64.go (about)

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