-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder_string_block.go
More file actions
183 lines (162 loc) · 4.27 KB
/
Copy pathdecoder_string_block.go
File metadata and controls
183 lines (162 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package vibejson
import "unsafe"
// decoderStringBlock is the header shared by fixed-size owned-string blocks.
// The common path allocates one concrete header+data object, so the cursor can
// retain its arena in one pointer without growing beyond one cache line.
type decoderStringBlock struct {
used int
capacity int
external []byte
}
type decoderStringBlock64 struct {
decoderStringBlock
data [64]byte
}
type decoderStringBlock128 struct {
decoderStringBlock
data [128]byte
}
type decoderStringBlock256 struct {
decoderStringBlock
data [256]byte
}
type decoderStringBlock512 struct {
decoderStringBlock
data [512]byte
}
type decoderStringBlock1K struct {
decoderStringBlock
data [1 << 10]byte
}
type decoderStringBlock2K struct {
decoderStringBlock
data [2 << 10]byte
}
type decoderStringBlock4K struct {
decoderStringBlock
data [4 << 10]byte
}
type decoderStringBlock8K struct {
decoderStringBlock
data [8 << 10]byte
}
type decoderStringBlock16K struct {
decoderStringBlock
data [16 << 10]byte
}
type decoderStringBlock32K struct {
decoderStringBlock
data [32 << 10]byte
}
type decoderStringBlock64K struct {
decoderStringBlock
data [64 << 10]byte
}
type decoderStringBlock128K struct {
decoderStringBlock
data [128 << 10]byte
}
type decoderStringBlock256K struct {
decoderStringBlock
data [256 << 10]byte
}
type decoderStringBlock512K struct {
decoderStringBlock
data [512 << 10]byte
}
type decoderStringBlock1M struct {
decoderStringBlock
data [1 << 20]byte
}
type decoderStringBlock2M struct {
decoderStringBlock
data [2 << 20]byte
}
type decoderStringBlock4M struct {
decoderStringBlock
data [4 << 20]byte
}
func newDecoderStringBlock(capacity int) *decoderStringBlock {
switch {
case capacity <= 64:
block := new(decoderStringBlock64)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 128:
block := new(decoderStringBlock128)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 256:
block := new(decoderStringBlock256)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 512:
block := new(decoderStringBlock512)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 1<<10:
block := new(decoderStringBlock1K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 2<<10:
block := new(decoderStringBlock2K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 4<<10:
block := new(decoderStringBlock4K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 8<<10:
block := new(decoderStringBlock8K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 16<<10:
block := new(decoderStringBlock16K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 32<<10:
block := new(decoderStringBlock32K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 64<<10:
block := new(decoderStringBlock64K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 128<<10:
block := new(decoderStringBlock128K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 256<<10:
block := new(decoderStringBlock256K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 512<<10:
block := new(decoderStringBlock512K)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 1<<20:
block := new(decoderStringBlock1M)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 2<<20:
block := new(decoderStringBlock2M)
block.capacity = len(block.data)
return &block.decoderStringBlock
case capacity <= 4<<20:
block := new(decoderStringBlock4M)
block.capacity = len(block.data)
return &block.decoderStringBlock
default:
block := new(decoderStringBlock)
block.external = make([]byte, capacity)
block.capacity = capacity
return block
}
}
func (block *decoderStringBlock) bytes() []byte {
if block.external != nil {
return block.external
}
data := unsafe.Add(unsafe.Pointer(block), unsafe.Sizeof(*block))
return unsafe.Slice((*byte)(data), block.capacity)
}