Merge pull request #1115 from quantified-uncertainty/map-efficiency

Slightly faster map and filter implementations
This commit is contained in:
Ozzie Gooen 2022-09-11 13:44:56 -07:00 committed by GitHub
commit d55c72f39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,16 +33,14 @@ module Internals = {
eLambdaValue, eLambdaValue,
reducer: ProjectReducerFnT.t, reducer: ProjectReducerFnT.t,
): ReducerInterface_InternalExpressionValue.t => { ): ReducerInterface_InternalExpressionValue.t => {
let mappedList = array->E.A.reduceReverse(list{}, (acc, elem) => { Belt.Array.map(array, elem =>
let newElem = Reducer_Expression_Lambda.doLambdaCall( Reducer_Expression_Lambda.doLambdaCall(
eLambdaValue, eLambdaValue,
list{elem}, list{elem},
(accessors: ProjectAccessorsT.t), (accessors: ProjectAccessorsT.t),
(reducer: ProjectReducerFnT.t), (reducer: ProjectReducerFnT.t),
) )
list{newElem, ...acc} )->Wrappers.evArray
})
mappedList->Belt.List.toArray->Wrappers.evArray
} }
let reduce = ( let reduce = (
@ -75,19 +73,18 @@ module Internals = {
accessors: ProjectAccessorsT.t, accessors: ProjectAccessorsT.t,
reducer: ProjectReducerFnT.t, reducer: ProjectReducerFnT.t,
) => { ) => {
let mappedList = aValueArray->Belt.Array.reduceReverse(list{}, (acc, elem) => { Js.Array2.filter(aValueArray, elem => {
let newElem = Reducer_Expression_Lambda.doLambdaCall( let result = Reducer_Expression_Lambda.doLambdaCall(
aLambdaValue, aLambdaValue,
list{elem}, list{elem},
accessors, accessors,
reducer, reducer,
) )
switch newElem { switch result {
| IEvBool(true) => list{elem, ...acc} | IEvBool(true) => true
| _ => acc | _ => false
} }
}) })->Wrappers.evArray
mappedList->Belt.List.toArray->Wrappers.evArray
} }
} }