auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton

libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it.

Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
This commit is contained in:
bors
2014-04-10 21:01:41 -07:00
66 changed files with 1070 additions and 983 deletions

View File

@@ -37,6 +37,7 @@ use std::cell::Cell;
use std::{cmp, os, path};
use std::io::fs;
use std::path::is_sep;
use std::strbuf::StrBuf;
/**
* An iterator that yields Paths from the filesystem that match a particular
@@ -310,7 +311,7 @@ impl Pattern {
* match the input string and nothing else.
*/
pub fn escape(s: &str) -> ~str {
let mut escaped = ~"";
let mut escaped = StrBuf::new();
for c in s.chars() {
match c {
// note that ! does not need escaping because it is only special inside brackets
@@ -324,7 +325,7 @@ impl Pattern {
}
}
}
escaped
escaped.into_owned()
}
/**
@@ -463,8 +464,8 @@ impl Pattern {
fn fill_todo(todo: &mut Vec<(Path, uint)>, patterns: &[Pattern], idx: uint, path: &Path,
options: MatchOptions) {
// convert a pattern that's just many Char(_) to a string
fn pattern_as_str(pattern: &Pattern) -> Option<~str> {
let mut s = ~"";
fn pattern_as_str(pattern: &Pattern) -> Option<StrBuf> {
let mut s = StrBuf::new();
for token in pattern.tokens.iter() {
match *token {
Char(c) => s.push_char(c),
@@ -494,8 +495,8 @@ fn fill_todo(todo: &mut Vec<(Path, uint)>, patterns: &[Pattern], idx: uint, path
// continue. So instead of passing control back to the iterator,
// we can just check for that one entry and potentially recurse
// right away.
let special = "." == s || ".." == s;
let next_path = path.join(s);
let special = "." == s.as_slice() || ".." == s.as_slice();
let next_path = path.join(s.as_slice());
if (special && path.is_dir()) || (!special && next_path.exists()) {
add(todo, next_path);
}