Skip to content

Commit 65df668

Browse files
committed
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.
1 parent 34555f1 commit 65df668

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ impl<'data> BorrowedBuf<'data> {
132132
#[inline]
133133
pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this> {
134134
BorrowedCursor {
135-
start: self.filled,
136135
// SAFETY: we never assign into `BorrowedCursor::buf`, so treating its
137136
// lifetime covariantly is safe.
138137
buf: unsafe {
@@ -188,9 +187,6 @@ pub struct BorrowedCursor<'a> {
188187
// we create a `BorrowedCursor`. This is only safe if we never replace `buf` by assigning into
189188
// it, so don't do that!
190189
buf: &'a mut BorrowedBuf<'a>,
191-
/// The length of the filled portion of the underlying buffer at the time of the cursor's
192-
/// creation.
193-
start: usize,
194190
}
195191

196192
impl<'a> BorrowedCursor<'a> {
@@ -208,7 +204,6 @@ impl<'a> BorrowedCursor<'a> {
208204
self.buf,
209205
)
210206
},
211-
start: self.start,
212207
}
213208
}
214209

@@ -218,13 +213,12 @@ impl<'a> BorrowedCursor<'a> {
218213
self.buf.capacity() - self.buf.filled
219214
}
220215

221-
/// Returns the number of bytes written to this cursor since it was created from a `BorrowedBuf`.
216+
/// Returns the number of bytes written to the `BorrowedBuf` this cursor was created from.
222217
///
223-
/// Note that if this cursor is a reborrowed clone of another, then the count returned is the
224-
/// count written via either cursor, not the count since the cursor was reborrowed.
218+
/// In particular, the count returned is shared by all reborrows of the cursor.
225219
#[inline]
226220
pub fn written(&self) -> usize {
227-
self.buf.filled - self.start
221+
self.buf.filled
228222
}
229223

230224
/// Returns a mutable reference to the initialized portion of the cursor.

library/coretests/tests/io/borrowed_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn reborrow_written() {
124124
assert_eq!(cursor2.written(), 32);
125125
assert_eq!(cursor.written(), 32);
126126

127-
assert_eq!(buf.unfilled().written(), 0);
127+
assert_eq!(buf.unfilled().written(), 32);
128128
assert_eq!(buf.init_len(), 32);
129129
assert_eq!(buf.filled().len(), 32);
130130
let filled = buf.filled();

0 commit comments

Comments
 (0)