Skip to content

Commit 9e3e7b7

Browse files
committed
New definition
1 parent fc44874 commit 9e3e7b7

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

base/filesystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import .Base:
141141
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
142142
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
143143
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
144-
isexecutable, isreadable, iswritable, MutableByteArray
144+
isexecutable, isreadable, iswritable, MutableDenseArrayType
145145

146146
import .Base.RefValue
147147

@@ -309,7 +309,7 @@ bytesavailable(f::File) = max(0, filesize(f) - position(f)) # position can be >
309309

310310
eof(f::File) = bytesavailable(f) == 0
311311

312-
function readbytes!(f::File, b::MutableByteArray, nb=length(b))
312+
function readbytes!(f::File, b::MutableDenseArrayType{UInt8}, nb=length(b))
313313
nr = min(nb, bytesavailable(f))
314314
if length(b) < nr
315315
resize!(b, nr)

base/iobuffer.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function read_sub(from::GenericIOBuffer, a::AbstractArray{T}, offs, nel) where T
219219
if offs+nel-1 > length(a) || offs < 1 || nel < 0
220220
throw(BoundsError())
221221
end
222-
if isbitstype(T) && isa(a,MutableByteArray)
222+
if isa(a, MutableDenseArrayType{UInt8})
223223
nb = UInt(nel * sizeof(T))
224224
GC.@preserve a unsafe_read(from, pointer(a, offs), nb)
225225
else
@@ -548,15 +548,8 @@ end
548548
return sizeof(UInt8)
549549
end
550550

551-
const MutableByteArray = Union{
552-
Array{UInt8},
553-
Memory{UInt8},
554-
FastContiguousSubArray{UInt8,<:Any,<:Array{UInt8}},
555-
FastContiguousSubArray{UInt8,<:Any,<:Memory{UInt8}},
556-
}
557-
558-
readbytes!(io::GenericIOBuffer, b::MutableByteArray, nb=length(b)) = readbytes!(io, b, Int(nb))
559-
function readbytes!(io::GenericIOBuffer, b::MutableByteArray, nb::Int)
551+
readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb))
552+
function readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb::Int)
560553
nr = min(nb, bytesavailable(io))
561554
if length(b) < nr
562555
resize!(b, nr)

base/iostream.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function copyuntil(out::IOStream, s::IOStream, delim::UInt8; keep::Bool=false)
486486
return out
487487
end
488488

489-
function readbytes_all!(s::IOStream, b::MutableByteArray, nb::Integer)
489+
function readbytes_all!(s::IOStream, b::MutableDenseArrayType{UInt8}, nb::Integer)
490490
olb = lb = length(b)
491491
nr = 0
492492
let l = s._dolock, slock = s.lock
@@ -514,7 +514,7 @@ function readbytes_all!(s::IOStream, b::MutableByteArray, nb::Integer)
514514
return nr
515515
end
516516

517-
function readbytes_some!(s::IOStream, b::MutableByteArray, nb::Integer)
517+
function readbytes_some!(s::IOStream, b::MutableDenseArrayType{UInt8}, nb::Integer)
518518
olb = length(b)
519519
if nb > olb
520520
resize!(b, nb)
@@ -543,7 +543,7 @@ requested bytes, until an error or end-of-file occurs. If `all` is `false`, at m
543543
`read` call is performed, and the amount of data returned is device-dependent. Note that not
544544
all stream types support the `all` option.
545545
"""
546-
function readbytes!(s::IOStream, b::MutableByteArray, nb=length(b); all::Bool=true)
546+
function readbytes!(s::IOStream, b::MutableDenseArrayType{UInt8}, nb=length(b); all::Bool=true)
547547
return all ? readbytes_all!(s, b, nb) : readbytes_some!(s, b, nb)
548548
end
549549

base/strings/string.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ function Base.showerror(io::IO, exc::StringIndexError)
2727
end
2828
end
2929

30-
const ByteArray = Union{
31-
DenseVector{<:Union{UInt8, Int8}},
32-
FastContiguousSubArray{<:Union{UInt8, Int8},1,<:DenseVector{<:Union{UInt8, Int8}}},
33-
}
34-
3530
@inline between(b::T, lo::T, hi::T) where {T<:Integer} = (lo b) & (b hi)
3631

3732
"""

base/subarray.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,24 @@ FastContiguousSubArray{T,N,P,I<:Union{Tuple{Union{Slice, AbstractUnitRange}, Var
348348
@inline _reindexlinear(V::FastContiguousSubArray, i::Int) = V.offset1 + i
349349
@inline _reindexlinear(V::FastContiguousSubArray, i::AbstractUnitRange{Int}) = V.offset1 .+ i
350350

351+
"""
352+
An internal type representing arrays stored contiguously in memory.
353+
"""
354+
const DenseArrayType{T,N} = Union{
355+
DenseArray{T,N},
356+
<:FastContiguousSubArray{T,N,<:DenseArray},
357+
}
358+
359+
"""
360+
An internal type representing mutable arrays stored contiguously in memory.
361+
"""
362+
const MutableDenseArrayType{T,N} = Union{
363+
Array{T, N},
364+
Memory{T},
365+
FastContiguousSubArray{T,N,<:Array},
366+
FastContiguousSubArray{T,N,<:Memory}
367+
}
368+
351369
# parents of FastContiguousSubArrays may support fast indexing with AbstractUnitRanges,
352370
# so we may just forward the indexing to the parent
353371
# This may only be done for non-offset ranges, as the result would otherwise have offset axes

base/util.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,7 @@ unsafe_crc32c(a, n, crc) = ccall(:jl_crc32c, UInt32, (UInt32, Ptr{UInt8}, Csize_
492492
_crc32c(a::NTuple{<:Any, UInt8}, crc::UInt32=0x00000000) =
493493
unsafe_crc32c(Ref(a), length(a) % Csize_t, crc)
494494

495-
function _crc32c(
496-
a::Union{DenseArray{UInt8}, FastContiguousSubArray{UInt8,N,<:DenseArray{UInt8}} where N},
497-
crc::UInt32=0x00000000
498-
)
495+
function _crc32c(a::DenseArrayType{UInt8}, crc::UInt32=0x00000000)
499496
unsafe_crc32c(a, length(a) % Csize_t, crc)
500497
end
501498

stdlib/CRC32c/src/CRC32c.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ See [`CRC32c.crc32c`](@ref) for more information.
88
module CRC32c
99

1010
import Base.FastContiguousSubArray
11+
import Base: DenseArrayType
1112

1213
export crc32c
1314

@@ -35,10 +36,7 @@ but note that the result may be endian-dependent.
3536
function crc32c end
3637

3738

38-
function crc32c(
39-
a::Union{DenseArray{UInt8}, FastContiguousSubArray{UInt8,N,<:DenseArray{UInt8}} where N},
40-
crc::UInt32=0x00000000
41-
)
39+
function crc32c(a::DenseArrayType{UInt8}, crc::UInt32=0x00000000)
4240
Base._crc32c(a, crc)
4341
end
4442

0 commit comments

Comments
 (0)