[libcxx-commits] [libcxx] [libc++] Optimize filebuf::seekoff (PR #211788)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 27 08:09:19 PDT 2026
================
@@ -995,24 +995,80 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
std::__throw_bad_cast();
int __width = __cv_->encoding();
- if (__file_ == nullptr || (__width <= 0 && __off != 0) || sync())
+ if (__file_ == nullptr || (__width <= 0 && __off != 0))
return pos_type(off_type(-1));
- // __width > 0 || __off == 0
- int __whence;
+
+ auto __byte_off = __width <= 0 ? 0 : __width * __off;
+
+ int __whence = 0;
switch (__way) {
- case ios_base::beg:
- __whence = SEEK_SET;
- break;
- case ios_base::cur:
+ case ios::beg: {
----------------
ldionne wrote:
Consider refactoring these three "seek position" cases into separate functions.
https://github.com/llvm/llvm-project/pull/211788
More information about the libcxx-commits
mailing list