Skip to content

Commit 85bc88d

Browse files
committed
BufWriter: use #[cold] and less aggressive #[inline] hints
1 parent 72aecbf commit 85bc88d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/std/src/io/buffered/bufwriter.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl<W: Write> BufWriter<W> {
351351
// If this function ends up being called frequently relative to `write`,
352352
// it's likely a sign that the client is using an improperly sized buffer
353353
// or their write patterns are somewhat pathological.
354+
#[cold]
354355
#[inline(never)]
355356
fn write_cold(&mut self, buf: &[u8]) -> io::Result<usize> {
356357
if buf.len() > self.spare_capacity() {
@@ -385,6 +386,7 @@ impl<W: Write> BufWriter<W> {
385386
// If this function ends up being called frequently relative to `write_all`,
386387
// it's likely a sign that the client is using an improperly sized buffer
387388
// or their write patterns are somewhat pathological.
389+
#[cold]
388390
#[inline(never)]
389391
fn write_all_cold(&mut self, buf: &[u8]) -> io::Result<()> {
390392
// Normally, `write_all` just calls `write` in a loop. We can do better
@@ -421,7 +423,7 @@ impl<W: Write> BufWriter<W> {
421423

422424
// SAFETY: Requires `buf.len() <= self.buf.capacity() - self.buf.len()`,
423425
// i.e., that input buffer length is less than or equal to spare capacity.
424-
#[inline(always)]
426+
#[inline]
425427
unsafe fn write_to_buffer_unchecked(&mut self, buf: &[u8]) {
426428
debug_assert!(buf.len() <= self.spare_capacity());
427429
let old_len = self.buf.len();

0 commit comments

Comments
 (0)