Skip to content

Commit

Permalink
Make is nodal check a bit faster
Browse files Browse the repository at this point in the history
The existence of the method is enough to mark nodality.  No need to
call it to find out.
  • Loading branch information
lizmat committed Jan 4, 2017
1 parent bd03adb commit 0f25d83
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/core/metaops.pm
Expand Up @@ -364,33 +364,43 @@ sub METAOP_HYPER(\op, *%opt) {

proto sub METAOP_HYPER_POSTFIX(|) {*}
multi sub METAOP_HYPER_POSTFIX(\op) {
op.?nodal
?? (-> \obj { nodemap(op, obj) })
!! (-> \obj { deepmap(op, obj) })
nqp::if(
nqp::can(op,"nodal"),
(-> \obj { nodemap(op, obj) }),
(-> \obj { deepmap(op, obj) })
)
}

# no indirection for subscripts and such
proto sub METAOP_HYPER_POSTFIX_ARGS(|) {*}
multi sub METAOP_HYPER_POSTFIX_ARGS(\obj,\op) {
op.?nodal
?? nodemap(op, obj)
!! deepmap(op, obj)
nqp::if(
nqp::can(op,"nodal"),
nodemap(op, obj),
deepmap(op, obj)
)
}
multi sub METAOP_HYPER_POSTFIX_ARGS(\obj, @args, \op) {
op.?nodal
?? nodemap( -> \o { op.(o,@args) }, obj )
!! deepmap( -> \o { op.(o,@args) }, obj );
nqp::if(
nqp::can(op,"nodal"),
nodemap( -> \o { op.(o,@args) }, obj ),
deepmap( -> \o { op.(o,@args) }, obj )
)
}
multi sub METAOP_HYPER_POSTFIX_ARGS(\obj, \args, \op) {
op.?nodal
?? nodemap( -> \o { op.(o,|args) }, obj )
!! deepmap( -> \o { op.(o,|args) }, obj );
nqp::if(
nqp::can(op,"nodal"),
nodemap( -> \o { op.(o,|args) }, obj ),
deepmap( -> \o { op.(o,|args) }, obj )
)
}

sub METAOP_HYPER_PREFIX(\op) {
op.?nodal # rarely true for prefixes
?? (-> \obj { nodemap(op, obj) })
!! (-> \obj { deepmap(op, obj) })
nqp::if(
nqp::can(op,"nodal"), # rarely true for prefixes
(-> \obj { nodemap(op, obj) }),
(-> \obj { deepmap(op, obj) })
)
}

sub METAOP_HYPER_CALL(\list, |args) { deepmap(-> $c { $c(|args) }, list) }
Expand Down Expand Up @@ -505,9 +515,11 @@ multi sub HYPER(&operator, Iterable:D \left, Iterable:D \right, :$dwim-left, :$d
}

multi sub HYPER(\op, \obj) {
op.?nodal
?? nodemap(op, obj)
!! deepmap(op,obj);
nqp::if(
nqp::can(op,"nodal"),
nodemap(op, obj),
deepmap(op,obj)
)
}

proto sub deepmap(|) { * }
Expand Down

0 comments on commit 0f25d83

Please sign in to comment.