Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions ext/standard/str_contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ public function execute(Frame $frame): void
$this->requireExactArgCount($frame, 'str_contains', 2);
InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_contains', 'haystack', 0, $frame);
InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_contains', 'needle', 1, $frame);
$haystackStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[0],
'str_contains',
0,
'haystack'
);
$needleStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[1],
'str_contains',
1,
'needle'
);
$haystackStr = self::vmStringArg($frame, 0, 'haystack');
$needleStr = self::vmStringArg($frame, 1, 'needle');
BuiltinExecute::writeReturn(
$frame,
static function (Variable $ret) use ($haystackStr, $needleStr): void {
Expand All @@ -68,9 +58,23 @@ public function call(Context $context, JITVariable ...$args): Value
}
JitInternalStrictArg::rejectNullString($context, $args[0], 'str_contains', 'haystack', 1);
JitInternalStrictArg::rejectNullString($context, $args[1], 'str_contains', 'needle', 2);
$hay = JitStringBuiltinArg::lower($context, $args[0], 'str_contains', 0, 'haystack');
$needle = JitStringBuiltinArg::lower($context, $args[1], 'str_contains', 1, 'needle');
$hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_contains', 0, 'haystack');
$needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_contains', 1, 'needle');

return StringStrContains::invokeContains($context, $hay, $needle);
}

private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string
{
if (InternalStrictArg::isCallerStrict($frame)) {
return InternalStrictArg::requireString($frame, $argIndex, 'str_contains', $paramName)->toString();
}

return VmString::coerceStringBuiltinArg(
$frame->calledArgs[$argIndex],
'str_contains',
$argIndex,
$paramName
);
}
}
32 changes: 18 additions & 14 deletions ext/standard/str_ends_with.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ public function execute(Frame $frame): void
$this->requireExactArgCount($frame, 'str_ends_with', 2);
InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_ends_with', 'haystack', 0, $frame);
InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_ends_with', 'needle', 1, $frame);
$haystackStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[0],
'str_ends_with',
0,
'haystack'
);
$needleStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[1],
'str_ends_with',
1,
'needle'
);
$haystackStr = self::vmStringArg($frame, 0, 'haystack');
$needleStr = self::vmStringArg($frame, 1, 'needle');
BuiltinExecute::writeReturn(
$frame,
static fn (Variable $ret) => $ret->bool(VmString::endsWith($haystackStr, $needleStr))
Expand All @@ -58,9 +48,23 @@ public function call(Context $context, JITVariable ...$args): Value
}
JitInternalStrictArg::rejectNullString($context, $args[0], 'str_ends_with', 'haystack', 1);
JitInternalStrictArg::rejectNullString($context, $args[1], 'str_ends_with', 'needle', 2);
$hay = JitStringBuiltinArg::lower($context, $args[0], 'str_ends_with', 0, 'haystack');
$needle = JitStringBuiltinArg::lower($context, $args[1], 'str_ends_with', 1, 'needle');
$hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_ends_with', 0, 'haystack');
$needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_ends_with', 1, 'needle');

return StringStrContains::invokeEndsWith($context, $hay, $needle);
}

private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string
{
if (InternalStrictArg::isCallerStrict($frame)) {
return InternalStrictArg::requireString($frame, $argIndex, 'str_ends_with', $paramName)->toString();
}

return VmString::coerceStringBuiltinArg(
$frame->calledArgs[$argIndex],
'str_ends_with',
$argIndex,
$paramName
);
}
}
32 changes: 18 additions & 14 deletions ext/standard/str_starts_with.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ public function execute(Frame $frame): void
$this->requireExactArgCount($frame, 'str_starts_with', 2);
InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_starts_with', 'haystack', 0, $frame);
InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_starts_with', 'needle', 1, $frame);
$haystackStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[0],
'str_starts_with',
0,
'haystack'
);
$needleStr = VmString::coerceStringBuiltinArgNoObject(
$frame->calledArgs[1],
'str_starts_with',
1,
'needle'
);
$haystackStr = self::vmStringArg($frame, 0, 'haystack');
$needleStr = self::vmStringArg($frame, 1, 'needle');
BuiltinExecute::writeReturn(
$frame,
static fn (Variable $ret) => $ret->bool(VmString::startsWith($haystackStr, $needleStr))
Expand All @@ -58,9 +48,23 @@ public function call(Context $context, JITVariable ...$args): Value
}
JitInternalStrictArg::rejectNullString($context, $args[0], 'str_starts_with', 'haystack', 1);
JitInternalStrictArg::rejectNullString($context, $args[1], 'str_starts_with', 'needle', 2);
$hay = JitStringBuiltinArg::lower($context, $args[0], 'str_starts_with', 0, 'haystack');
$needle = JitStringBuiltinArg::lower($context, $args[1], 'str_starts_with', 1, 'needle');
$hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_starts_with', 0, 'haystack');
$needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_starts_with', 1, 'needle');

return StringStrContains::invokeStartsWith($context, $hay, $needle);
}

private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string
{
if (InternalStrictArg::isCallerStrict($frame)) {
return InternalStrictArg::requireString($frame, $argIndex, 'str_starts_with', $paramName)->toString();
}

return VmString::coerceStringBuiltinArg(
$frame->calledArgs[$argIndex],
'str_starts_with',
$argIndex,
$paramName
);
}
}