mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-23 21:41:34 +00:00
Merge pull request #7364 from Ruan-pysoft/master
Fix slice.simple_equal misbehaviour on empty slice with non-nil data
This commit is contained in:
@@ -357,6 +357,17 @@ simple_equal :: proc "contextless" (a, b: $T/[]$E) -> bool where intrinsics.type
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
if len(a) == 0 {
|
||||
// Empty slices are always equivalent to each other.
|
||||
//
|
||||
// This check is here in the event that a slice with a `data` of
|
||||
// nil is compared against a slice with a non-nil `data` but a
|
||||
// length of zero.
|
||||
//
|
||||
// In that case, `memory_compare` would return -1 or +1 because one
|
||||
// of the pointers is nil.
|
||||
return true
|
||||
}
|
||||
return runtime.memory_compare(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user