Skip to content

Commit 00653af

Browse files
committed
---
yaml --- r: 232764 b: refs/heads/try c: 6065678 h: refs/heads/master v: v3
1 parent 3a1a049 commit 00653af

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 7723550fdd7fe29bee9dcbd45bdef4f209a7e1f1
4+
refs/heads/try: 6065678e627643cc3275c677408d11f48802595e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libstd/sys/unix/os.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use sys::c;
3030
use sys::fd;
3131
use vec;
3232

33-
const GETCWD_BUF_BYTES: usize = 2048;
3433
const TMPBUF_SZ: usize = 128;
3534

3635
/// Returns the platform-specific value of errno
@@ -94,11 +93,9 @@ pub fn error_string(errno: i32) -> String {
9493
}
9594

9695
pub fn getcwd() -> io::Result<PathBuf> {
97-
let mut buf = Vec::new();
98-
let mut n = GETCWD_BUF_BYTES;
96+
let mut buf = Vec::with_capacity(512);
9997
loop {
10098
unsafe {
101-
buf.reserve(n);
10299
let ptr = buf.as_mut_ptr() as *mut libc::c_char;
103100
if !libc::getcwd(ptr, buf.capacity() as libc::size_t).is_null() {
104101
let len = CStr::from_ptr(buf.as_ptr() as *const libc::c_char).to_bytes().len();
@@ -111,7 +108,12 @@ pub fn getcwd() -> io::Result<PathBuf> {
111108
return Err(error);
112109
}
113110
}
114-
n *= 2;
111+
112+
// Trigger the internal buffer resizing logic of `Vec` by requiring
113+
// more space than the current capacity.
114+
let cap = buf.capacity();
115+
buf.set_len(cap);
116+
buf.reserve(1);
115117
}
116118
}
117119
}

0 commit comments

Comments
 (0)