Skip to content

Commit bee184d

Browse files
committed
Various minor performance improvements.
1 parent 6ee1f86 commit bee184d

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

Cvd.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Cvd handler (last modified: 2022.02.12).
3+
* Cvd handler (last modified: 2026.03.18).
44
* @link https://github.com/phpMussel/SigTool/blob/master/Cvd.php
55
*
66
* Adapted from phpMussel's TarHandler class.
@@ -53,22 +53,22 @@ public function __construct(string $File)
5353
{
5454
/** Attempt to open the file. */
5555
if (
56-
!is_readable($File) ||
57-
!is_file($File) ||
58-
!is_resource(($Handle = fopen($File, 'rb')))
56+
!\is_readable($File) ||
57+
!\is_file($File) ||
58+
!\is_resource(($Handle = \fopen($File, 'rb')))
5959
) {
6060
$this->ErrorState = 2;
6161
return;
6262
}
6363

6464
/** Attempt to read the file. */
65-
while (!feof($Handle)) {
66-
$this->Data .= fread($Handle, 131072);
65+
while (!\feof($Handle)) {
66+
$this->Data .= \fread($Handle, 131072);
6767
}
68-
fclose($Handle);
68+
\fclose($Handle);
6969

7070
/** Set total size. */
71-
$this->TotalSize = strlen($this->Data);
71+
$this->TotalSize = \strlen($this->Data);
7272

7373
/** Guard. */
7474
if ($this->TotalSize <= 512) {
@@ -77,13 +77,13 @@ public function __construct(string $File)
7777
}
7878

7979
/** Attempt to decompress the cvd data. */
80-
$this->Data = gzdecode(substr($this->Data, 512));
80+
$this->Data = \gzdecode(\substr($this->Data, 512));
8181

8282
/** Pad the cvd data. */
83-
$this->Data .= str_repeat("\0", 512 - (strlen($this->Data) % 512));
83+
$this->Data .= \str_repeat("\0", 512 - (\strlen($this->Data) % 512));
8484

8585
/** Adjust total size. */
86-
if (($this->TotalSize = strlen($this->Data)) < 1) {
86+
if (($this->TotalSize = \strlen($this->Data)) < 1) {
8787
$this->ErrorState = 2;
8888
return;
8989
}
@@ -104,7 +104,7 @@ public function EntryRead(int $Bytes = -1): string
104104
if ($Bytes < 0 || $Bytes > $Actual) {
105105
$Bytes = $Actual;
106106
}
107-
return substr($this->Data, $this->Offset + 512, $Bytes);
107+
return \substr($this->Data, $this->Offset + 512, $Bytes);
108108
}
109109

110110
/**
@@ -114,7 +114,7 @@ public function EntryRead(int $Bytes = -1): string
114114
*/
115115
public function EntryActualSize(): int
116116
{
117-
return octdec(preg_replace('/\D/', '', substr($this->Data, $this->Offset + 124, 12))) ?: 0;
117+
return \octdec(\preg_replace('/\D/', '', \substr($this->Data, $this->Offset + 124, 12))) ?: 0;
118118
}
119119

120120
/**
@@ -125,7 +125,7 @@ public function EntryActualSize(): int
125125
public function EntryIsDirectory(): bool
126126
{
127127
$Name = $this->EntryName();
128-
$Separator = substr($Name, -1, 1);
128+
$Separator = \substr($Name, -1, 1);
129129
return (($Separator === "\\" || $Separator === '/') && $this->EntryActualSize() === 0);
130130
}
131131

@@ -137,7 +137,7 @@ public function EntryIsDirectory(): bool
137137
*/
138138
public function EntryName(): string
139139
{
140-
return preg_replace('/[^\x20-\xff]/', '', substr($this->Data, $this->Offset, 100));
140+
return \preg_replace('/[^\x20-\xff]/', '', \substr($this->Data, $this->Offset, 100));
141141
}
142142

143143
/**

SigTool.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* SigTool v2.0.2 (last modified: 2026.03.17).
3+
* SigTool v2.0.2 (last modified: 2026.03.18).
44
* @link https://github.com/phpMussel/SigTool
55
*
66
* Generates signatures for phpMussel using main.cvd and daily.cvd from ClamAV.
@@ -25,7 +25,7 @@ class SigTool extends \Maikuolan\Common\YAML
2525
/**
2626
* @var string Last modified date.
2727
*/
28-
public const MODIFIED = '2026.03.17';
28+
public const MODIFIED = '2026.03.18';
2929

3030
/**
3131
* @var int Safe file chunk size for when reading files.
@@ -62,8 +62,8 @@ public function readIn(): bool
6262
*/
6363
public function setRaw(string $Raw)
6464
{
65-
if (substr($Raw, 0, 4) === "---\n") {
66-
$Raw = substr($Raw, 4);
65+
if (\substr($Raw, 0, 4) === "---\n") {
66+
$Raw = \substr($Raw, 4);
6767
}
6868
$this->Raw = $Raw;
6969
}
@@ -259,7 +259,7 @@ private function formatSize(int $Size): string
259259

260260
/** L10N. */
261261
$L10N = [
262-
'Help' => sprintf(
262+
'Help' => \sprintf(
263263
" SigTool v%s (last modified: %s).\n\n%s",
264264
SigTool::VERSION,
265265
SigTool::MODIFIED,
@@ -288,7 +288,7 @@ private function formatSize(int $Size): string
288288
* Terminate with debug information.
289289
*/
290290
$Terminate = function ($Err = '_Error_Other', $Msg = '') use (&$SigTool, &$L10N) {
291-
$Debug = \debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
291+
$Debug = \debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
292292
$SigTool->outputMessage(\sprintf($L10N[$Err] ?? $L10N['_Error_Other'], $Debug['line'], $Msg), true);
293293
echo "\n\n";
294294
die;
@@ -502,10 +502,10 @@ private function formatSize(int $Size): string
502502
}
503503

504504
/** NDB sequence. */
505-
if (is_readable($SigTool->fixPath(__DIR__ . '/clamav.ndb'))) {
505+
if (\is_readable($SigTool->fixPath(__DIR__ . '/clamav.ndb'))) {
506506
$SigTool->outputMessage(\sprintf($L10N['Accessing'], 'clamav.ndb'), true);
507507
$FileData = '';
508-
if (!is_resource($Handle = \fopen($SigTool->fixPath(__DIR__ . '/clamav.ndb'), 'rb'))) {
508+
if (!\is_resource($Handle = \fopen($SigTool->fixPath(__DIR__ . '/clamav.ndb'), 'rb'))) {
509509
$SigTool->outputMessage(\sprintf($L10N['Accessing'], 'clamav.ndb') . $L10N['Failed']);
510510
} else {
511511
while (!\feof($Handle)) {

YAML.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* YAML handler (last modified: 2026.03.17).
3+
* YAML handler (last modified: 2026.03.18).
44
*
55
* This file is a part of the "common classes package", utilised by a number of
66
* packages and projects, including CIDRAM and phpMussel.
@@ -674,9 +674,9 @@ private function normaliseValue(string &$Value, bool $EnforceScalar = false): vo
674674
} elseif (\preg_match('~^0x[\dA-Fa-f]+$~', $Value)) {
675675
$Value = \hexdec(\str_replace('_', '', \substr($Value, 2)));
676676
} elseif (\preg_match('~^0o[0-8]+$~', $Value)) {
677-
$Value = octdec(\str_replace('_', '', \substr($Value, 2)));
677+
$Value = \octdec(\str_replace('_', '', \substr($Value, 2)));
678678
} elseif (\preg_match('~^0b[01]+$~', $Value)) {
679-
$Value = bindec(\str_replace('_', '', \substr($Value, 2)));
679+
$Value = \bindec(\str_replace('_', '', \substr($Value, 2)));
680680
} elseif (\preg_match('~^\d+$~', $Value)) {
681681
$Value = (int)\str_replace('_', '', $Value);
682682
} elseif (\preg_match('~^(?:\d+\.\d+|\d+(?:\.\d+)?[Ee][-+]\d+)$~', $Value)) {
@@ -921,7 +921,7 @@ private function processInner(array $Arr, string &$Out, int $Depth = 0): void
921921
$Value = $Value->Data;
922922
}
923923
if (\is_array($Value)) {
924-
if ($Sequential && key($Value) !== 0 && $Depth < $this->FlowRebuildDepth - 2) {
924+
if ($Sequential && \key($Value) !== 0 && $Depth < $this->FlowRebuildDepth - 2) {
925925
$Append = '';
926926
$this->processInner($Value, $Append, $Depth + 2);
927927
$Out .= \substr($Append, $Depth + 1);
@@ -1194,7 +1194,7 @@ private function coerce($Value, bool $EnforceScalar, string $Tag)
11941194

11951195
/** Unserialising a PHP object. */
11961196
if ($Tag === 'php/object') {
1197-
return $this->AllowObjectUnserialize && \is_string($Value) && $Value !== '' ? unserialize($Value) : $Value;
1197+
return $this->AllowObjectUnserialize && \is_string($Value) && $Value !== '' ? \unserialize($Value) : $Value;
11981198
}
11991199

12001200
/** For extending with other non-scalar coercion. */
@@ -1607,7 +1607,7 @@ private function scalarToString($In): string
16071607
}
16081608
if (\is_object($In)) {
16091609
if ($this->AllowObjectSerialize) {
1610-
return '!php/object ' . $this->Quotes . $this->escape(serialize($In)) . $this->Quotes;
1610+
return '!php/object ' . $this->Quotes . $this->escape(\serialize($In)) . $this->Quotes;
16111611
} elseif (\method_exists($In, '__toString')) {
16121612
return $this->Quotes . $this->escape((string)$In) . $this->Quotes;
16131613
}

0 commit comments

Comments
 (0)