11
11
# |<-------->||<-------->||<-------->|
12
12
# |....xxxxxxxxxxxxXXXXXXXXXXXX...........|
13
13
# ^ ^ ^ ^ ^
14
- # 1 markpos bufferpos marginpos endof (data)
14
+ # 1 markpos bufferpos marginpos lastindex (data)
15
15
#
16
16
# `markpos` is positive iff there are marked data; otherwise it is set to zero.
17
17
# `markpos` ≤ `bufferpos` ≤ `marginpos` must hold whenever possible.
@@ -27,7 +27,7 @@ mutable struct Buffer
27
27
total:: Int64
28
28
29
29
function Buffer (size:: Integer )
30
- return new (Vector {UInt8} (size), 0 , 1 , 1 , 0 )
30
+ return new (Vector {UInt8} (uninitialized, size), 0 , 1 , 1 , 0 )
31
31
end
32
32
33
33
function Buffer (data:: Vector{UInt8} )
@@ -56,7 +56,7 @@ function marginptr(buf::Buffer)
56
56
end
57
57
58
58
function marginsize (buf:: Buffer )
59
- return endof (buf. data) - buf. marginpos + 1
59
+ return lastindex (buf. data) - buf. marginpos + 1
60
60
end
61
61
62
62
function marginmem (buf:: Buffer )
@@ -140,7 +140,7 @@ function makemargin!(buf::Buffer, minsize::Integer)
140
140
datapos = buf. markpos
141
141
datasize = buf. marginpos - buf. markpos
142
142
end
143
- copy ! (buf. data, 1 , buf. data, datapos, datasize)
143
+ copyto ! (buf. data, 1 , buf. data, datapos, datasize)
144
144
shift = datapos - 1
145
145
if buf. markpos > 0
146
146
buf. markpos -= shift
@@ -181,15 +181,15 @@ end
181
181
function takemarked! (buf:: Buffer )
182
182
@assert buf. markpos > 0
183
183
sz = buf. marginpos - buf. markpos
184
- copy ! (buf. data, 1 , buf. data, buf. markpos, sz)
184
+ copyto ! (buf. data, 1 , buf. data, buf. markpos, sz)
185
185
initbuffer! (buf)
186
186
return resize! (buf. data, sz)
187
187
end
188
188
189
189
# Copy data from `data` to `buf`.
190
190
function copydata! (buf:: Buffer , data:: Ptr{UInt8} , nbytes:: Integer )
191
191
makemargin! (buf, nbytes)
192
- unsafe_copy ! (marginptr (buf), data, nbytes)
192
+ unsafe_copyto ! (marginptr (buf), data, nbytes)
193
193
supplied! (buf, nbytes)
194
194
return buf
195
195
end
@@ -199,16 +199,16 @@ function copydata!(data::Ptr{UInt8}, buf::Buffer, nbytes::Integer)
199
199
# NOTE: It's caller's responsibility to ensure that the buffer has at least
200
200
# nbytes.
201
201
@assert buffersize (buf) ≥ nbytes
202
- unsafe_copy ! (data, bufferptr (buf), nbytes)
202
+ unsafe_copyto ! (data, bufferptr (buf), nbytes)
203
203
consumed! (buf, nbytes)
204
204
return data
205
205
end
206
206
207
207
# Insert data to the current buffer.
208
208
function insertdata! (buf:: Buffer , data:: Ptr{UInt8} , nbytes:: Integer )
209
209
makemargin! (buf, nbytes)
210
- copy ! (buf. data, buf. bufferpos + nbytes, buf. data, buf. bufferpos, buffersize (buf))
211
- unsafe_copy ! (bufferptr (buf), data, nbytes)
210
+ copyto ! (buf. data, buf. bufferpos + nbytes, buf. data, buf. bufferpos, buffersize (buf))
211
+ unsafe_copyto ! (bufferptr (buf), data, nbytes)
212
212
supplied! (buf, nbytes)
213
213
return buf
214
214
end
0 commit comments