vitess.io/vitess@v0.16.2/go/tools/sizegen/integration/cached_size.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  // Code generated by Sizegen. DO NOT EDIT.
    17  
    18  package integration
    19  
    20  import (
    21  	"math"
    22  	"reflect"
    23  	"unsafe"
    24  
    25  	hack "vitess.io/vitess/go/hack"
    26  )
    27  
    28  type cachedObject interface {
    29  	CachedSize(alloc bool) int64
    30  }
    31  
    32  func (cached *A) CachedSize(alloc bool) int64 {
    33  	if cached == nil {
    34  		return int64(0)
    35  	}
    36  	size := int64(0)
    37  	if alloc {
    38  		size += int64(16)
    39  	}
    40  	return size
    41  }
    42  func (cached *Bimpl) CachedSize(alloc bool) int64 {
    43  	if cached == nil {
    44  		return int64(0)
    45  	}
    46  	size := int64(0)
    47  	if alloc {
    48  		size += int64(8)
    49  	}
    50  	return size
    51  }
    52  func (cached *C) CachedSize(alloc bool) int64 {
    53  	if cached == nil {
    54  		return int64(0)
    55  	}
    56  	size := int64(0)
    57  	if alloc {
    58  		size += int64(16)
    59  	}
    60  	// field field1 vitess.io/vitess/go/tools/sizegen/integration.B
    61  	if cc, ok := cached.field1.(cachedObject); ok {
    62  		size += cc.CachedSize(true)
    63  	}
    64  	return size
    65  }
    66  func (cached *D) CachedSize(alloc bool) int64 {
    67  	if cached == nil {
    68  		return int64(0)
    69  	}
    70  	size := int64(0)
    71  	if alloc {
    72  		size += int64(8)
    73  	}
    74  	// field field1 *vitess.io/vitess/go/tools/sizegen/integration.Bimpl
    75  	if cached.field1 != nil {
    76  		size += hack.RuntimeAllocSize(int64(8))
    77  	}
    78  	return size
    79  }
    80  
    81  //go:nocheckptr
    82  func (cached *Map1) CachedSize(alloc bool) int64 {
    83  	if cached == nil {
    84  		return int64(0)
    85  	}
    86  	size := int64(0)
    87  	if alloc {
    88  		size += int64(8)
    89  	}
    90  	// field field1 map[uint8]uint8
    91  	if cached.field1 != nil {
    92  		size += int64(48)
    93  		hmap := reflect.ValueOf(cached.field1)
    94  		numBuckets := int(math.Pow(2, float64((*(*uint8)(unsafe.Pointer(hmap.Pointer() + uintptr(9)))))))
    95  		numOldBuckets := (*(*uint16)(unsafe.Pointer(hmap.Pointer() + uintptr(10))))
    96  		size += hack.RuntimeAllocSize(int64(numOldBuckets * 32))
    97  		if len(cached.field1) > 0 || numBuckets > 1 {
    98  			size += hack.RuntimeAllocSize(int64(numBuckets * 32))
    99  		}
   100  	}
   101  	return size
   102  }
   103  
   104  //go:nocheckptr
   105  func (cached *Map2) CachedSize(alloc bool) int64 {
   106  	if cached == nil {
   107  		return int64(0)
   108  	}
   109  	size := int64(0)
   110  	if alloc {
   111  		size += int64(8)
   112  	}
   113  	// field field1 map[uint64]vitess.io/vitess/go/tools/sizegen/integration.A
   114  	if cached.field1 != nil {
   115  		size += int64(48)
   116  		hmap := reflect.ValueOf(cached.field1)
   117  		numBuckets := int(math.Pow(2, float64((*(*uint8)(unsafe.Pointer(hmap.Pointer() + uintptr(9)))))))
   118  		numOldBuckets := (*(*uint16)(unsafe.Pointer(hmap.Pointer() + uintptr(10))))
   119  		size += hack.RuntimeAllocSize(int64(numOldBuckets * 208))
   120  		if len(cached.field1) > 0 || numBuckets > 1 {
   121  			size += hack.RuntimeAllocSize(int64(numBuckets * 208))
   122  		}
   123  	}
   124  	return size
   125  }
   126  
   127  //go:nocheckptr
   128  func (cached *Map3) CachedSize(alloc bool) int64 {
   129  	if cached == nil {
   130  		return int64(0)
   131  	}
   132  	size := int64(0)
   133  	if alloc {
   134  		size += int64(8)
   135  	}
   136  	// field field1 map[uint64]vitess.io/vitess/go/tools/sizegen/integration.B
   137  	if cached.field1 != nil {
   138  		size += int64(48)
   139  		hmap := reflect.ValueOf(cached.field1)
   140  		numBuckets := int(math.Pow(2, float64((*(*uint8)(unsafe.Pointer(hmap.Pointer() + uintptr(9)))))))
   141  		numOldBuckets := (*(*uint16)(unsafe.Pointer(hmap.Pointer() + uintptr(10))))
   142  		size += hack.RuntimeAllocSize(int64(numOldBuckets * 208))
   143  		if len(cached.field1) > 0 || numBuckets > 1 {
   144  			size += hack.RuntimeAllocSize(int64(numBuckets * 208))
   145  		}
   146  		for _, v := range cached.field1 {
   147  			if cc, ok := v.(cachedObject); ok {
   148  				size += cc.CachedSize(true)
   149  			}
   150  		}
   151  	}
   152  	return size
   153  }
   154  func (cached *Padded) CachedSize(alloc bool) int64 {
   155  	if cached == nil {
   156  		return int64(0)
   157  	}
   158  	size := int64(0)
   159  	if alloc {
   160  		size += int64(24)
   161  	}
   162  	return size
   163  }
   164  func (cached *Slice1) CachedSize(alloc bool) int64 {
   165  	if cached == nil {
   166  		return int64(0)
   167  	}
   168  	size := int64(0)
   169  	if alloc {
   170  		size += int64(24)
   171  	}
   172  	// field field1 []vitess.io/vitess/go/tools/sizegen/integration.A
   173  	{
   174  		size += hack.RuntimeAllocSize(int64(cap(cached.field1)) * int64(16))
   175  	}
   176  	return size
   177  }
   178  func (cached *Slice2) CachedSize(alloc bool) int64 {
   179  	if cached == nil {
   180  		return int64(0)
   181  	}
   182  	size := int64(0)
   183  	if alloc {
   184  		size += int64(24)
   185  	}
   186  	// field field1 []vitess.io/vitess/go/tools/sizegen/integration.B
   187  	{
   188  		size += hack.RuntimeAllocSize(int64(cap(cached.field1)) * int64(16))
   189  		for _, elem := range cached.field1 {
   190  			if cc, ok := elem.(cachedObject); ok {
   191  				size += cc.CachedSize(true)
   192  			}
   193  		}
   194  	}
   195  	return size
   196  }
   197  func (cached *Slice3) CachedSize(alloc bool) int64 {
   198  	if cached == nil {
   199  		return int64(0)
   200  	}
   201  	size := int64(0)
   202  	if alloc {
   203  		size += int64(24)
   204  	}
   205  	// field field1 []*vitess.io/vitess/go/tools/sizegen/integration.Bimpl
   206  	{
   207  		size += hack.RuntimeAllocSize(int64(cap(cached.field1)) * int64(8))
   208  		for _, elem := range cached.field1 {
   209  			if elem != nil {
   210  				size += hack.RuntimeAllocSize(int64(8))
   211  			}
   212  		}
   213  	}
   214  	return size
   215  }
   216  func (cached *String1) CachedSize(alloc bool) int64 {
   217  	if cached == nil {
   218  		return int64(0)
   219  	}
   220  	size := int64(0)
   221  	if alloc {
   222  		size += int64(24)
   223  	}
   224  	// field field1 string
   225  	size += hack.RuntimeAllocSize(int64(len(cached.field1)))
   226  	return size
   227  }