Skip to content

Commit

Permalink
Merge pull request #33 from kuszmaul/bck-better-bounds-check
Browse files Browse the repository at this point in the history
Better bounds check
  • Loading branch information
kuszmaul authored Nov 5, 2024
2 parents b192b5b + 6812899 commit dd10a13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function Base.:-(blob1::Blob, blob2::Blob)
getfield(blob1, :offset) - getfield(blob2, :offset)
end

@inline function boundscheck(blob::Blob{T}) where T
@boundscheck begin
function boundscheck(blob::Blob{T}) where T
begin
if (getfield(blob, :offset) < 0) || (getfield(blob, :offset) + self_size(T) > getfield(blob, :limit))
throw(BoundsError(blob))
end
Expand All @@ -51,7 +51,7 @@ end
end

Base.@propagate_inbounds function Base.getindex(blob::Blob{T}) where T
boundscheck(blob)
@boundscheck boundscheck(blob)
unsafe_load(blob)
end

Expand Down Expand Up @@ -103,7 +103,7 @@ end
end

Base.@propagate_inbounds function Base.setindex!(blob::Blob{T}, value::T) where T
boundscheck(blob)
@boundscheck boundscheck(blob)
unsafe_store!(blob, value)
end

Expand Down

0 comments on commit dd10a13

Please sign in to comment.