Skip to content

Commit

Permalink
use === for String, String equality. (#27790)
Browse files Browse the repository at this point in the history
* use === for String, String equality

* do pointer equality check before memory check

* remove whitespace

* Update base/strings/string.jl

Co-Authored-By: oxinabox <[email protected]>

* Update base/strings/string.jl

Co-Authored-By: oxinabox <[email protected]>
  • Loading branch information
oxinabox authored and ararslan committed Jan 18, 2019
1 parent 30c6ee7 commit eb18db5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ function cmp(a::String, b::String)
end

function ==(a::String, b::String)
pointer_from_objref(a) == pointer_from_objref(b) && return true
al = sizeof(a)
al == sizeof(b) && 0 == ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, al)
return al == sizeof(b) && 0 == ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, al)
end

typemin(::Type{String}) = ""
Expand Down

2 comments on commit eb18db5

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.