From e0be63cf32c0ead99bc7a4f2ea4c6f111bb8e45c Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 23 Sep 2020 23:34:19 +0000 Subject: [PATCH] Bug 1642951 - Don't open the underlying file unnecessarily when seeking nsFileInputStream to the start. r=baku,necko-reviewers,valentin Differential Revision: https://phabricator.services.mozilla.com/D91088 --- netwerk/base/nsFileStreams.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/netwerk/base/nsFileStreams.cpp b/netwerk/base/nsFileStreams.cpp index 5193c8fb141a..41526c76423a 100644 --- a/netwerk/base/nsFileStreams.cpp +++ b/netwerk/base/nsFileStreams.cpp @@ -522,6 +522,12 @@ nsresult nsFileInputStream::SeekInternal(int32_t aWhence, int64_t aOffset, aWhence = NS_SEEK_SET; aOffset += mCachedPosition; } + // If we're trying to seek to the start then we're done, so + // return early to avoid Seek from calling DoPendingOpen and + // opening the underlying file earlier than necessary. + if (aWhence == NS_SEEK_SET && aOffset == 0) { + return NS_OK; + } } else { return NS_BASE_STREAM_CLOSED; }