authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-04 10:37:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-04 10:37:19-04:00
log0454e610bf8627537855ce96e922dfbe7322e4a1
tree147aad66b962bc5dbd0dc39a7d24eac96755fbc5
parent20b1491e6bd87b10e822282c5867604d634973a1

std: take advantage of new while syntax


2 files changed, 5 insertions(+), 12 deletions(-)

std/os/index.zig+3-8
...@@ -276,9 +276,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con...@@ -276,9 +276,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
276 {276 {
277 var it = env_map.iterator();277 var it = env_map.iterator();
278 var i: usize = 0;278 var i: usize = 0;
279 while (true) : (i += 1) {279 while (it.next()) |pair| : (i += 1) {
280 const pair = it.next() ?? break;
281
282 const env_buf = %return allocator.alloc(u8, pair.key.len + pair.value.len + 2);280 const env_buf = %return allocator.alloc(u8, pair.key.len + pair.value.len + 2);
283 @memcpy(&env_buf[0], pair.key.ptr, pair.key.len);281 @memcpy(&env_buf[0], pair.key.ptr, pair.key.len);
284 env_buf[pair.key.len] = '=';282 env_buf[pair.key.len] = '=';
...@@ -310,8 +308,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con...@@ -310,8 +308,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
310 var it = mem.split(PATH, ':');308 var it = mem.split(PATH, ':');
311 var seen_eacces = false;309 var seen_eacces = false;
312 var err: usize = undefined;310 var err: usize = undefined;
313 while (true) {311 while (it.next()) |search_path| {
314 const search_path = it.next() ?? break;
315 mem.copy(u8, path_buf, search_path);312 mem.copy(u8, path_buf, search_path);
316 path_buf[search_path.len] = '/';313 path_buf[search_path.len] = '/';
317 mem.copy(u8, path_buf[search_path.len + 1 ...], exe_path);314 mem.copy(u8, path_buf[search_path.len + 1 ...], exe_path);
...@@ -689,9 +686,7 @@ start_over:...@@ -689,9 +686,7 @@ start_over:
689 var full_entry_buf = List(u8).init(allocator);686 var full_entry_buf = List(u8).init(allocator);
690 defer full_entry_buf.deinit();687 defer full_entry_buf.deinit();
691688
692 while (true) {689 while (%return dir.next()) |entry| {
693 const entry = (%return dir.next()) ?? break;
694
695 %return full_entry_buf.resize(full_path.len + entry.name.len + 1);690 %return full_entry_buf.resize(full_path.len + entry.name.len + 1);
696 const full_entry_path = full_entry_buf.toSlice();691 const full_entry_path = full_entry_buf.toSlice();
697 mem.copy(u8, full_entry_path, full_path);692 mem.copy(u8, full_entry_path, full_path);
std/os/path.zig+2-4
...@@ -112,8 +112,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {...@@ -112,8 +112,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
112112
113 for (paths[first_index...]) |p, i| {113 for (paths[first_index...]) |p, i| {
114 var it = mem.split(p, '/');114 var it = mem.split(p, '/');
115 while (true) {115 while (it.next()) |component| {
116 const component = it.next() ?? break;
117 if (mem.eql(u8, component, ".")) {116 if (mem.eql(u8, component, ".")) {
118 continue;117 continue;
119 } else if (mem.eql(u8, component, "..")) {118 } else if (mem.eql(u8, component, "..")) {
...@@ -248,8 +247,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u...@@ -248,8 +247,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u
248 continue;247 continue;
249 }248 }
250 var up_count: usize = 1;249 var up_count: usize = 1;
251 while (true) {250 while (from_it.next()) |_| {
252 _ = from_it.next() ?? break;
253 up_count += 1;251 up_count += 1;
254 }252 }
255 const up_index_end = up_count * "../".len;253 const up_index_end = up_count * "../".len;