github.com/goccy/go-json@v0.10.3-0.20240509105655-5e2ae3f23c1d/internal/encoder/compiler_norace.go (about)

     1  //go:build !race
     2  // +build !race
     3  
     4  package encoder
     5  
     6  func CompileToGetCodeSet(ctx *RuntimeContext, typeptr uintptr) (*OpcodeSet, error) {
     7  	if typeptr > typeAddr.MaxTypeAddr || typeptr < typeAddr.BaseTypeAddr {
     8  		codeSet, err := compileToGetCodeSetSlowPath(typeptr)
     9  		if err != nil {
    10  			return nil, err
    11  		}
    12  		return getFilteredCodeSetIfNeeded(ctx, codeSet)
    13  	}
    14  	index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
    15  	if codeSet := cachedOpcodeSets[index]; codeSet != nil {
    16  		filtered, err := getFilteredCodeSetIfNeeded(ctx, codeSet)
    17  		if err != nil {
    18  			return nil, err
    19  		}
    20  		return filtered, nil
    21  	}
    22  	codeSet, err := newCompiler().compile(typeptr)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	filtered, err := getFilteredCodeSetIfNeeded(ctx, codeSet)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	cachedOpcodeSets[index] = codeSet
    31  	return filtered, nil
    32  }