mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
Some: allocate slice to keep track unused indexes is not necessary
Waste of memory for those unused indexes. It got replaced by a simple boolean to keep track of it.
This commit is contained in:
@@ -122,15 +122,15 @@ func Some(slice, function interface{}) bool {
|
|||||||
panic("Filter function must be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String())
|
panic("Filter function must be of type func(int, " + elemType.String() + ")" + reflect.ValueOf(true).Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
var indexes []int
|
has := false
|
||||||
for i := 0; i < sv.Len(); i++ {
|
for i := 0; i < sv.Len(); i++ {
|
||||||
flag := fn.Call([]reflect.Value{reflect.ValueOf(i), sv.Index(i)})[0]
|
flag := fn.Call([]reflect.Value{reflect.ValueOf(i), sv.Index(i)})[0]
|
||||||
if flag.Bool() {
|
if flag.Bool() {
|
||||||
indexes = append(indexes, i)
|
has = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(indexes) > 0
|
return has
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter iterates over elements of slice, returning an slice of all elements `signature` returns truthy for.
|
// Filter iterates over elements of slice, returning an slice of all elements `signature` returns truthy for.
|
||||||
|
|||||||
Reference in New Issue
Block a user