diff options
| author | Benoît du Garreau <benoit@dugarreau.fr> | 2025-07-09 18:11:27 +0200 |
|---|---|---|
| committer | Benoît du Garreau <benoit@dugarreau.fr> | 2025-07-09 18:11:27 +0200 |
| commit | 65df66831f3fdb7f20a74e843a46bb90993221eb (patch) | |
| tree | 88dcf0c7e38eab0cb87e57af65ad56f012068ba7 /library | |
| parent | 34555f1b0b49e4fd944b2cb9c298f15b6b5da144 (diff) | |
| download | rust-65df66831f3fdb7f20a74e843a46bb90993221eb.tar.gz rust-65df66831f3fdb7f20a74e843a46bb90993221eb.zip | |
core: Change `BorrowedCursor::written`'s origin
This enable removing the `start` field, so `BorrowedCursor` fits in a single register. Because `written` is almost always used in difference with another call, this changes nothing else in practice.
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/io/borrowed_buf.rs | 12 | ||||
| -rw-r--r-- | library/coretests/tests/io/borrowed_buf.rs | 2 |
2 files changed, 4 insertions, 10 deletions
diff --git a/library/core/src/io/borrowed_buf.rs b/library/core/src/io/borrowed_buf.rs index bd468c9ee85..b2f10d93b39 100644 --- a/library/core/src/io/borrowed_buf.rs +++ b/library/core/src/io/borrowed_buf.rs @@ -132,7 +132,6 @@ impl<'data> BorrowedBuf<'data> { #[inline] pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this> { BorrowedCursor { - start: self.filled, // SAFETY: we never assign into `BorrowedCursor::buf`, so treating its // lifetime covariantly is safe. buf: unsafe { @@ -188,9 +187,6 @@ pub struct BorrowedCursor<'a> { // we create a `BorrowedCursor`. This is only safe if we never replace `buf` by assigning into // it, so don't do that! buf: &'a mut BorrowedBuf<'a>, - /// The length of the filled portion of the underlying buffer at the time of the cursor's - /// creation. - start: usize, } impl<'a> BorrowedCursor<'a> { @@ -208,7 +204,6 @@ impl<'a> BorrowedCursor<'a> { self.buf, ) }, - start: self.start, } } @@ -218,13 +213,12 @@ impl<'a> BorrowedCursor<'a> { self.buf.capacity() - self.buf.filled } - /// Returns the number of bytes written to this cursor since it was created from a `BorrowedBuf`. + /// Returns the number of bytes written to the `BorrowedBuf` this cursor was created from. /// - /// Note that if this cursor is a reborrowed clone of another, then the count returned is the - /// count written via either cursor, not the count since the cursor was reborrowed. + /// In particular, the count returned is shared by all reborrows of the cursor. #[inline] pub fn written(&self) -> usize { - self.buf.filled - self.start + self.buf.filled } /// Returns a mutable reference to the initialized portion of the cursor. diff --git a/library/coretests/tests/io/borrowed_buf.rs b/library/coretests/tests/io/borrowed_buf.rs index 60829109d50..869fc31fee9 100644 --- a/library/coretests/tests/io/borrowed_buf.rs +++ b/library/coretests/tests/io/borrowed_buf.rs @@ -124,7 +124,7 @@ fn reborrow_written() { assert_eq!(cursor2.written(), 32); assert_eq!(cursor.written(), 32); - assert_eq!(buf.unfilled().written(), 0); + assert_eq!(buf.unfilled().written(), 32); assert_eq!(buf.init_len(), 32); assert_eq!(buf.filled().len(), 32); let filled = buf.filled(); |
