From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3759 invoked by alias); 9 Nov 2019 16:28:35 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 3748 invoked by uid 89); 9 Nov 2019 16:28:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=seek, whence, initially, positions X-HELO: mail-wm1-f68.google.com Received: from mail-wm1-f68.google.com (HELO mail-wm1-f68.google.com) (209.85.128.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Nov 2019 16:28:33 +0000 Received: by mail-wm1-f68.google.com with SMTP id f3so9180934wmc.5 for ; Sat, 09 Nov 2019 08:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Fj6BZ3XyfvYkONDogrbX1OSkoFP0EhAaXRe72s4qcOI=; b=eIHKhqoUaU03vwUxgQ0b36MNrR4HSZ/xUpv4/F4KB2thVhyxZ8Fs0h1jEH5Lu0iVzq RjuCihkOTL/KIZrxTMvJMlfKyFQxkXGHT7FFecKaNpa8Uk8mS16LYHctXYUZsTNBNx4Z r2om3vK4CoYbBP87O2lv0gOJkM8LZDWshzjk3XfM3asRz64SSj1BjbtfpysjHkHFSNK9 AS8Xd19JrPBgXNh2bPyDSWapOlpAn+uZ3JiPijDsayu62ML5W3voXz3j+6Ust4lhch93 YaxeRLh/+JCGBvmVZfVdylwbRXMyizDTrudOYdBNDh71uVAo1Or/xLT/tjCjxNhU3QfM ysSg== Return-Path: Received: from localhost.localdomain (176-190-176-101.abo.bbox.fr. [176.190.176.101]) by smtp.googlemail.com with ESMTPSA id c24sm22005207wrb.27.2019.11.09.08.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Nov 2019 08:28:30 -0800 (PST) From: Bastien Bouclet To: newlib@sourceware.org Cc: Bastien Bouclet Subject: [PATCH] newlib: fix fseek optimization with SEEK_CUR Date: Sat, 09 Nov 2019 16:28:00 -0000 Message-Id: <20191109162804.1905160-1-bastien.bouclet@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2019/txt/msg00636.txt.bz2 The call to fflush was invalidating the read buffer, preventing relative seeks to positions that would have been inside the read buffer from being optimized. The call to srefill would then re-read mostly the same data that was initially in the read buffer. --- newlib/libc/stdio/fseeko.c | 31 ++++++------------------------- newlib/libc/stdio64/fseeko64.c | 31 ++++++------------------------- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/newlib/libc/stdio/fseeko.c b/newlib/libc/stdio/fseeko.c index 3e0f9e90b..bbf1af43e 100644 --- a/newlib/libc/stdio/fseeko.c +++ b/newlib/libc/stdio/fseeko.c @@ -141,31 +141,12 @@ _fseeko_r (struct _reent *ptr, switch (whence) { case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset a la - * ftell (see ftell for details). - */ - _fflush_r (ptr, fp); /* may adjust seek offset on append stream */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else - { - curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); - if (curoff == -1L) - { - _newlib_flockfile_exit (fp); - return EOF; - } - } - if (fp->_flags & __SRD) - { - curoff -= fp->_r; - if (HASUB (fp)) - curoff -= fp->_ur; - } - else if (fp->_flags & __SWR && fp->_p != NULL) - curoff += fp->_p - fp->_bf._base; + curoff = _ftello_r(ptr, fp); + if (curoff == -1L) + { + _newlib_flockfile_exit (fp); + return EOF; + } offset += curoff; whence = SEEK_SET; diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c index 0672086a3..f38005570 100644 --- a/newlib/libc/stdio64/fseeko64.c +++ b/newlib/libc/stdio64/fseeko64.c @@ -142,31 +142,12 @@ _fseeko64_r (struct _reent *ptr, switch (whence) { case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset a la - * ftell (see ftell for details). - */ - _fflush_r (ptr, fp); /* may adjust seek offset on append stream */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else - { - curoff = seekfn (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR); - if (curoff == -1L) - { - _newlib_flockfile_exit(fp); - return EOF; - } - } - if (fp->_flags & __SRD) - { - curoff -= fp->_r; - if (HASUB (fp)) - curoff -= fp->_ur; - } - else if (fp->_flags & __SWR && fp->_p != NULL) - curoff += fp->_p - fp->_bf._base; + curoff = _ftello64_r(ptr, fp); + if (curoff == -1L) + { + _newlib_flockfile_exit (fp); + return EOF; + } offset += curoff; whence = SEEK_SET; -- 2.24.0