From 89bcc4843ac880ddda9ac00185a704f05b450145 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 9 Feb 2022 12:31:27 +0000 Subject: [PATCH] Code Modernization: Use `stream_get_contents()` in `POMO_FileReader::read_all()`. `stream_get_contents()` is faster than `fread()`, because the PHP core can decide how to best read the remaining file; it could decide to issue just one `read()` call or `mmap()` the file first. Per the PHP manual, `file_get_contents()` or `stream_get_contents()` is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by the OS to enhance performance. Reference: [https://www.php.net/manual/en/function.file-get-contents.php PHP Manual: file_get_contents()]. Follow-up to [12174]. Props maxkellermann. See #55069. git-svn-id: https://develop.svn.wordpress.org/trunk@52696 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pomo/streams.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/wp-includes/pomo/streams.php b/src/wp-includes/pomo/streams.php index e95dc17076..6a971af065 100644 --- a/src/wp-includes/pomo/streams.php +++ b/src/wp-includes/pomo/streams.php @@ -217,11 +217,7 @@ if ( ! class_exists( 'POMO_FileReader', false ) ) : * @return string */ public function read_all() { - $all = ''; - while ( ! $this->feof() ) { - $all .= $this->read( 4096 ); - } - return $all; + return stream_get_contents( $this->_f ); } } endif;