Skip to content

Commit fa3dd1a

Browse files
committed
Memory efficiency: Use integers instead of strings for deferred initializations
1 parent 0019bb2 commit fa3dd1a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/php/lang/ast/emit/PHP.class.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ protected function emitParameter($result, $parameter) {
289289
$this->emitOne($result, $parameter->default);
290290
} else {
291291
$result->out->write('=null');
292-
$result->locals['$']['null === $'.$parameter->name.' && $'.$parameter->name]= $parameter->default;
292+
$result->locals[1]['null === $'.$parameter->name.' && $'.$parameter->name]= $parameter->default;
293293
}
294294
}
295295
$result->locals[$parameter->name]= true;
@@ -351,7 +351,7 @@ protected function emitLambda($result, $lambda) {
351351

352352
protected function emitClass($result, $class) {
353353
array_unshift($result->meta, []);
354-
$result->locals= ['$' => [], '@' => []];
354+
$result->locals= [[], []];
355355

356356
$result->out->write(implode(' ', $class->modifiers).' class '.$this->declaration($class->name));
357357
$class->parent && $result->out->write(' extends '.$class->parent);
@@ -363,14 +363,14 @@ protected function emitClass($result, $class) {
363363

364364
// Create constructor for property initializations to non-static scalars
365365
// which have not already been emitted inside constructor
366-
if ($result->locals['$']) {
366+
if ($result->locals[1]) {
367367
$result->out->write('public function __construct() {');
368-
$this->emitInitializations($result, $result->locals['$']);
368+
$this->emitInitializations($result, $result->locals[1]);
369369
$result->out->write('}');
370370
}
371371

372372
$result->out->write('static function __init() {');
373-
$this->emitInitializations($result, $result->locals['@']);
373+
$this->emitInitializations($result, $result->locals[0]);
374374
$this->emitMeta($result, $class->name, $class->annotations, $class->comment);
375375
$result->out->write('}} '.$class->name.'::__init();');
376376
}
@@ -520,9 +520,9 @@ protected function emitProperty($result, $property) {
520520
$result->out->write('=');
521521
$this->emitOne($result, $property->expression);
522522
} else if (in_array('static', $property->modifiers)) {
523-
$result->locals['@']['self::$'.$property->name]= $property->expression;
523+
$result->locals[0]['self::$'.$property->name]= $property->expression;
524524
} else {
525-
$result->locals['$']['$this->'.$property->name]= $property->expression;
525+
$result->locals[1]['$this->'.$property->name]= $property->expression;
526526
}
527527
}
528528
$result->out->write(';');
@@ -532,11 +532,11 @@ protected function emitMethod($result, $method) {
532532

533533
// Include non-static initializations for members in constructor, removing
534534
// them to signal emitClass() no constructor needs to be generated.
535-
if ('__construct' === $method->name && isset($result->locals['$'])) {
536-
$locals= ['this' => true, '$' => $result->locals['$']];
537-
$result->locals['$']= [];
535+
if ('__construct' === $method->name && isset($result->locals[1])) {
536+
$locals= ['this' => true, 1 => $result->locals[1]];
537+
$result->locals[1]= [];
538538
} else {
539-
$locals= ['this' => true, '$' => []];
539+
$locals= ['this' => true, 1 => []];
540540
}
541541
$result->stack[]= $result->locals;
542542
$result->locals= $locals;
@@ -556,7 +556,7 @@ protected function emitMethod($result, $method) {
556556
foreach ($method->signature->parameters as $param) {
557557
if (isset($param->promote)) {
558558
$promoted.= $param->promote.' $'.$param->name.';';
559-
$result->locals['$']['$this->'.$param->name]= new Code(($param->reference ? '&$' : '$').$param->name);
559+
$result->locals[1]['$this->'.$param->name]= new Code(($param->reference ? '&$' : '$').$param->name);
560560
$result->meta[0][self::PROPERTY][$param->name]= [
561561
DETAIL_RETURNS => $param->type ? $param->type->name() : 'var',
562562
DETAIL_ANNOTATIONS => [],
@@ -573,7 +573,7 @@ protected function emitMethod($result, $method) {
573573
$result->out->write(';');
574574
} else {
575575
$result->out->write(' {');
576-
$this->emitInitializations($result, $result->locals['$']);
576+
$this->emitInitializations($result, $result->locals[1]);
577577
$this->emitAll($result, $method->body);
578578
$result->out->write('}');
579579
}

0 commit comments

Comments
 (0)