Skip to content

Commit 0271b9c

Browse files
committed
Optimize arguments popper
1 parent 12689fc commit 0271b9c

4 files changed

Lines changed: 5 additions & 22 deletions

File tree

src/Kernel/Mnemonics/_invokespecial.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPJava\Exceptions\UnableToCatchException;
77
use PHPJava\Kernel\Attributes\CodeAttribute;
88
use PHPJava\Kernel\Structures\_ExceptionTable;
9+
use PHPJava\Utilities\AttributionResolver;
910
use PHPJava\Utilities\BinaryTool;
1011
use PHPJava\Utilities\Formatter;
1112
use PHPJava\Utilities\MethodNameResolver;
@@ -26,8 +27,8 @@ public function execute(): void
2627
$parsedSignature = Formatter::parseSignature($signature);
2728
$invokerClass = $this->popFromOperandStack();
2829

29-
$arguments = [];
3030

31+
$arguments = array_fill(0, $parsedSignature['arguments_count'] - 1, null);
3132
for ($i = $parsedSignature['arguments_count'] - 1; $i >= 0; $i--) {
3233
$arguments[$i] = $this->popFromOperandStack();
3334
}
@@ -61,21 +62,6 @@ public function execute(): void
6162
...$arguments
6263
);
6364
} else {
64-
$reflectionClass = new \ReflectionClass(
65-
$realInvokerClass = TypeResolver::convertPHPTypeToJavaType($invokerClass)
66-
);
67-
$methodAccessor = $reflectionClass->getMethod($methodName);
68-
69-
if ($document = $methodAccessor->getDocComment()) {
70-
$prependInjections = $this->getNativeAnnotateInjections($document);
71-
if (!empty($prependInjections)) {
72-
array_unshift(
73-
$arguments,
74-
...$prependInjections
75-
);
76-
}
77-
}
78-
7965
$result = call_user_func_array(
8066
[
8167
$invokerClass,

src/Kernel/Mnemonics/_invokestatic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function execute(): void
2424
$cp = $cpInfo[$this->readUnsignedShort()];
2525
$methodName = $cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getNameIndex()]->getString();
2626
$signature = Formatter::parseSignature($cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getDescriptorIndex()]->getString());
27-
$arguments = [];
2827

2928
$this->getOptions('class_resolver')
3029
->resolve($cpInfo[$cpInfo[$cp->getClassIndex()]->getClassIndex()]->getString());
3130
[$resourceType, $classObject] = $this->getOptions('class_resolver')
3231
->resolve($cpInfo[$cpInfo[$cp->getClassIndex()]->getClassIndex()]->getString());
3332

33+
$arguments = array_fill(0, $signature['arguments_count'] - 1, null);
3434
for ($i = $signature['arguments_count'] - 1; $i >= 0; $i--) {
3535
$arguments[$i] = $this->popFromOperandStack();
3636
}

src/Kernel/Mnemonics/_invokevirtual.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function execute(): void
2828

2929
// signature
3030
$signature = Formatter::parseSignature($cpInfo[$nameAndTypeIndex->getDescriptorIndex()]->getString());
31-
$arguments = [];
3231

32+
$arguments = array_fill(0, $signature['arguments_count'] - 1, null);
3333
for ($i = $signature['arguments_count'] - 1; $i >= 0; $i--) {
3434
$arguments[$i] = $this->popFromOperandStack();
3535
}

src/Kernel/Types/Type.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ class Type
1313
public function __construct($value)
1414
{
1515
// Validate value which is scalar.
16-
if (!is_int($value) &&
17-
!is_float($value) &&
18-
!is_string($value) &&
19-
!is_bool($value) &&
16+
if (!is_scalar($value) &&
2017
!is_array($value) &&
2118
!is_null($value) &&
2219
!($value instanceof self)

0 commit comments

Comments
 (0)