Make WordPress Core

Ticket #55069: 0001-pomo-streams-use-stream_get_contents-in-read_all.patch

File 0001-pomo-streams-use-stream_get_contents-in-read_all.patch, 1.1 KB (added by maxkellermann, 3 years ago)

Suggested patch

  • src/wp-includes/pomo/streams.php

    From 34abb3748b391146941fc0769f8291e136f7c018 Mon Sep 17 00:00:00 2001
    From: Max Kellermann <mk@cm4all.com>
    Date: Thu, 3 Feb 2022 22:57:53 +0100
    Subject: [PATCH] pomo/streams: use stream_get_contents() in read_all()
    
    stream_get_contents() is faster, because the PHP core can decide how
    to best read the reamining file; it could decide to issue just one
    read() call or mmap() the file first.
    
    The old chunk size of 4 kB was rather clumsy, because it is smaller
    than PHP's default stream buffer size of 8 kB.
    ---
     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 b if ( ! class_exists( 'POMO_FileReader', false ) ) : 
    217217                 * @return string
    218218                 */
    219219                public function read_all() {
    220                         $all = '';
    221                         while ( ! $this->feof() ) {
    222                                 $all .= $this->read( 4096 );
    223                         }
    224                         return $all;
     220                        return stream_get_contents( $this->_f );
    225221                }
    226222        }
    227223endif;