Skip to content

Commit

Permalink
NativeCall: make no-setup-needed case less expensive
Browse files Browse the repository at this point in the history
by moving the setup code into a private method.
  • Loading branch information
timo committed Sep 29, 2015
1 parent 5b3872c commit 058e713
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/NativeCall.pm
Expand Up @@ -216,22 +216,24 @@ my role Native[Routine $r, $libname where Str|Callable] {
has Mu $!rettype;
has $!cpp-name-mangler;

method !setup() {
my $guessed_libname = guess_library_name($libname);
$!cpp-name-mangler = %lib{$guessed_libname} //
(%lib{$guessed_libname} = guess-name-mangler($r, $guessed_libname));
my Mu $arg_info := param_list_for($r.signature, $r);
my str $conv = self.?native_call_convention || '';
nqp::buildnativecall(self,
nqp::unbox_s($guessed_libname), # library name
nqp::unbox_s(gen_native_symbol($r, :$!cpp-name-mangler)), # symbol to call
nqp::unbox_s($conv), # calling convention
$arg_info,
return_hash_for($r.signature, $r));
$!setup = 1;
$!rettype := nqp::decont(map_return_type($r.returns));
}

method CALL-ME(|args) {
unless $!setup {
my $guessed_libname = guess_library_name($libname);
$!cpp-name-mangler = %lib{$guessed_libname} //
(%lib{$guessed_libname} = guess-name-mangler($r, $guessed_libname));
my Mu $arg_info := param_list_for($r.signature, $r);
my str $conv = self.?native_call_convention || '';
nqp::buildnativecall(self,
nqp::unbox_s($guessed_libname), # library name
nqp::unbox_s(gen_native_symbol($r, :$!cpp-name-mangler)), # symbol to call
nqp::unbox_s($conv), # calling convention
$arg_info,
return_hash_for($r.signature, $r));
$!setup = 1;
$!rettype := nqp::decont(map_return_type($r.returns));
}
self!setup unless $!setup;

my Mu $args := nqp::getattr(nqp::decont(args), Capture, '$!list');
if nqp::elems($args) != $r.signature.arity {
Expand Down

0 comments on commit 058e713

Please sign in to comment.