Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Uses static cache for finfo variable

Author Dave Jarvis <email>
Date 2026-02-18 12:15:55 GMT-0800
Commit 6e05d40d7565db2b2851e0e0072009d996147e0b
Parent 56ee5fd
File.php
];
+ private static $finfo;
+
private string $name;
private string $sha;
$this->timestamp = $timestamp;
$this->size = $size;
- $this->isDir = $mode === self::MODE_DIR || $mode === self::MODE_DIR_LONG;
+ $this->isDir = $mode === self::MODE_DIR ||
+ $mode === self::MODE_DIR_LONG;
$buffer = $this->isDir ? '' : $contents;
}
- public function highlight( FileRenderer $renderer, string $content ): string {
+ public function highlight(
+ FileRenderer $renderer,
+ string $content
+ ): string {
return $renderer->highlight( $this->name, $content, $this->mediaType );
+ }
+
+ public function isDir(): bool {
+ return $this->isDir;
}
private function detectMediaType( string $buffer ): string {
+ if( self::$finfo === null ) {
+ self::$finfo = new finfo( FILEINFO_MIME_TYPE );
+ }
+
return $buffer === ''
? self::MEDIA_EMPTY
- : ((new finfo( FILEINFO_MIME_TYPE ))->buffer( $buffer ) ?:
- self::MEDIA_OCTET);
+ : (self::$finfo->buffer( $buffer ) ?: self::MEDIA_OCTET);
}
Delta 17 lines added, 4 lines removed, 13-line increase