github.com/orijtech/structslop@v0.0.9-0.20230520012622-069644583b8b/testdata/src/struct/p.go.golden (about)

     1  // Copyright 2020 Orijtech, Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package p
    16  
    17  import "net/http/httptest"
    18  
    19  type s struct{}
    20  
    21  type s1 struct {
    22  	i int
    23  }
    24  
    25  type s2 struct {
    26  	i int
    27  	j int
    28  }
    29  
    30  type s3 struct { // want `struct has size 24 \(size class 24\), could be 16 \(size class 16\), you'll save 33.33% if you rearrange it to:\nstruct {\n\ty uint64\n\tx uint32\n\tz uint32\n}`
    31  	y uint64
    32  	x uint32
    33  	z uint32
    34  }
    35  
    36  type s4 struct { // want `struct has size 40 \(size class 48\), could be 24 \(size class 24\), you'll save 50.00% if you rearrange it to:\nstruct {\n\t_  \[0\]func\(\)\n\ti1 int\n\ti2 int\n\ta3 \[3\]bool\n\tb  bool\n}`
    37  	_  [0]func()
    38  	i1 int
    39  	i2 int
    40  	a3 [3]bool
    41  	b  bool
    42  }
    43  
    44  // should be good, the struct has size 32, can be rearrange to have size 24, but runtime allocator
    45  // allocate the same size class 32.
    46  type s5 struct { // want `struct has size 32 \(size class 32\), could be 24 \(size class 24\), you'll save 25.00% if you rearrange it to:\nstruct {\n\ty uint64\n\tz \*s\n\tx uint32\n\tt uint32\n}`
    47  	y uint64
    48  	z *s
    49  	x uint32
    50  	t uint32
    51  }
    52  
    53  type s6 struct { // should be good, see #16
    54  	bytep *uint8
    55  	mask  uint8
    56  	index uintptr
    57  }
    58  
    59  type s7 struct { // want `struct has size 40 \(size class 48\), could be 32 \(size class 32\), you'll save 33.33% if you rearrange it to:\nstruct {\n\ty uint64\n\tt \*httptest.Server\n\tw uint64\n\tx uint32\n\tz uint32\n}`
    60  	y uint64
    61  	t *httptest.Server
    62  	w uint64
    63  	x uint32
    64  	z uint32
    65  }
    66  
    67  type s8 struct { // want `struct has size 40 \(size class 48\), could be 32 \(size class 32\), you'll save 33.33% if you rearrange it to:\nstruct {\n\ty uint64\n\tt \*s\n\tw uint64\n\tx uint32\n\tz uint32\n}`
    68  	y uint64
    69  	t *s
    70  	w uint64
    71  	x uint32
    72  	z uint32
    73  }
    74  
    75  // Struct which combines multiple fields of the same type, see issue #41.
    76  type s9 struct { // want `struct has size 40 \(size class 48\), could be 24 \(size class 24\), you'll save 50.00% if you rearrange it to:\nstruct {\n\t_  \[0\]func\(\)\n\ti1 int\n\ti2 int\n\ta3 \[3\]bool\n\tb  bool\n}`
    77  	_      [0]func()
    78  	i1, i2 int
    79  	a3     [3]bool
    80  	b      bool
    81  }
    82  
    83  // Preserve comments.
    84  type s10 struct { // want `struct has size 40 \(size class 48\), could be 24 \(size class 24\), you'll save 50.00% if you rearrange it to:\nstruct {\n\t_  \[0\]func\(\)\n\ti1 int\n\ti2 int\n\ta3 \[3\]bool\n\tb  bool\n}`
    85  	_      [0]func()
    86  	i1, i2 int     // i1, i2 are int
    87  	a3     [3]bool // a3 is array of bool
    88  	b      bool    // b is bool
    89  }