Skip to content

ensure that the input String is GC preserved in equality check #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/InlineStrings.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module InlineStrings

import Base: ==

export InlineString, InlineStringType, inlinestrings
export @inline_str

Expand Down Expand Up @@ -290,14 +288,16 @@ macro inline_str(ex)
end


(==)(x::T, y::T) where {T <: InlineString} = Base.eq_int(x, y)
function ==(x::String, y::T) where {T <: InlineString}
Base.:(==)(x::T, y::T) where {T <: InlineString} = Base.eq_int(x, y)
function Base.:(==)(x::String, y::T) where {T <: InlineString}
sizeof(x) == sizeof(y) || return false
ref = Ref{T}(_bswap(y))
return ccall(:memcmp, Cint, (Ptr{UInt8}, Ref{T}, Csize_t),
pointer(x), ref, sizeof(x)) == 0
GC.@preserve x begin
return ccall(:memcmp, Cint, (Ptr{UInt8}, Ref{T}, Csize_t),
pointer(x), ref, sizeof(x)) == 0
end
end
==(y::InlineString, x::String) = x == y
Base.:(==)(y::InlineString, x::String) = x == y

Base.cmp(a::T, b::T) where {T <: InlineString} =
Base.eq_int(a, b) ? 0 : Base.ult_int(a, b) ? -1 : 1
Expand Down
Loading