Skip to content

Commit

Permalink
perf: Use casting instead of intval() or strval()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Feb 27, 2020
1 parent 99388a3 commit d93fa68
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Bencode.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public static function decode($data, &$pos = 0)
*/
private static function checkInteger($value)
{
$int = intval($value);
if (strval($int) !== $value) {
$int = (int)$value;
if ((string)$int !== $value) {
throw new ParseErrorException('Invalid integer format or integer overflow: ' . $value);
}
return $int;
Expand Down Expand Up @@ -140,7 +140,7 @@ public static function encode($data)
$return .= 'd';
ksort($data, SORT_STRING);
foreach ($data as $key => $value) {
$return .= self::encode(strval($key));
$return .= self::encode((string)$key);
$return .= self::encode($value);
}
}
Expand Down

0 comments on commit d93fa68

Please sign in to comment.