Skip to content

Commit

Permalink
Use a shared preallocated null capture
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 4, 2010
1 parent 680f033 commit 7aef582
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public abstract class Variable : IP6 {

public abstract IP6 GetVar();

public static readonly Variable[] None = new Variable[0];

public override DynMetaObject GetMO() { return null; }
}

Expand Down Expand Up @@ -939,7 +941,7 @@ public static Frame StartP6Thread(Frame th, IP6 sub) {
th.MarkSharedChain();
Thread thr = new Thread(delegate () {
Frame mark = new Frame(th, null, ExitRunloopSI);
Frame cur = sub.Invoke(mark, new Variable[0], null);
Frame cur = sub.Invoke(mark, Variable.None, null);
RunCore(cur);
});
thr.Start();
Expand Down
2 changes: 1 addition & 1 deletion perf/callmark.pl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
sub x29 () { x28; x28 } # 536870911
sub x30 () { x29; x29 } # 1073741823

x27;
x30;
1 change: 1 addition & 0 deletions src/CLRTypes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ my %typedata = (
'Lexer.RunProtoregex' => [m => 'IP6[]'],
'Lexer.GetLexer' => [m => 'Lexer'],
'Variable.None' => [f => 'Variable[]'],
'Kernel.SearchForHandler' => [c => 'Variable'],
'Kernel.Die' => [c => 'Variable'],
'Kernel.BindFail' => [c => 'Variable'],
Expand Down
10 changes: 9 additions & 1 deletion src/CodeGen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ use CLRTypes;
my $quick = 1;
for (@$sig) { $quick &&= ($_ eq '') }
my ($inv, @vals) = _odds(@args);
if ($quick) {
if (!@vals) {
return $inv, "Variable.None", "null";
} elsif ($quick) {
return $inv, "new Variable[] { " . join(", ", @vals) . "}", "null";
} else {
# TODO: optimize harder
Expand Down Expand Up @@ -299,11 +301,17 @@ use CLRTypes;

sub clr_new_arr {
my ($self, $class, @args) = @_;
if ($class eq 'Variable' && !@args) {
return "Variable[]", "Variable.None";
}
$class . "[]", "new $class []{" . join(", ", _odds @args) . "}";
}

sub clr_new_zarr {
my ($self, $class, $nity, $nitems) = @_;
if ($class eq 'Variable' && $nitems eq "0") {
return "Variable[]", "Variable.None";
}
$class . "[]", "(new $class [$nitems])";
}

Expand Down

0 comments on commit 7aef582

Please sign in to comment.