Skip to content

Commit 0d4cc45

Browse files
committed
---
yaml --- r: 11258 b: refs/heads/master c: bcbe36b h: refs/heads/master v: v3
1 parent 07ff1d8 commit 0d4cc45

File tree

11 files changed

+101
-149
lines changed

11 files changed

+101
-149
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 69834646d2efd2170236b1f8db3a71c77e378c5b
2+
refs/heads/master: bcbe36b33b7d310d64abeb76231cd3bd8b5cd584
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/comp/back/link.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,10 @@ fn link_binary(sess: session,
568568
// Converts a library file name into a cc -l argument
569569
fn unlib(config: @session::config, filename: str) -> str unsafe {
570570
let rmlib = fn@(filename: str) -> str {
571-
let found = str::find_bytes(filename, "lib");
572571
if config.os == session::os_macos ||
573572
(config.os == session::os_linux ||
574573
config.os == session::os_freebsd) &&
575-
option::is_some(found) && option::get(found) == 0u {
574+
str::find(filename, "lib") == 0 {
576575
ret str::unsafe::slice_bytes(filename, 3u,
577576
str::len_bytes(filename));
578577
} else { ret filename; }

trunk/src/comp/driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,28 +269,28 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
269269
}
270270

271271
fn get_os(triple: str) -> option<session::os> {
272-
ret if str::contains(triple, "win32") ||
273-
str::contains(triple, "mingw32") {
272+
ret if str::find(triple, "win32") >= 0 ||
273+
str::find(triple, "mingw32") >= 0 {
274274
some(session::os_win32)
275-
} else if str::contains(triple, "darwin") {
275+
} else if str::find(triple, "darwin") >= 0 {
276276
some(session::os_macos)
277-
} else if str::contains(triple, "linux") {
277+
} else if str::find(triple, "linux") >= 0 {
278278
some(session::os_linux)
279-
} else if str::contains(triple, "freebsd") {
279+
} else if str::find(triple, "freebsd") >= 0 {
280280
some(session::os_freebsd)
281281
} else { none };
282282
}
283283

284284
fn get_arch(triple: str) -> option<session::arch> {
285-
ret if str::contains(triple, "i386") || str::contains(triple, "i486") ||
286-
str::contains(triple, "i586") ||
287-
str::contains(triple, "i686") ||
288-
str::contains(triple, "i786") {
285+
ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
286+
str::find(triple, "i586") >= 0 ||
287+
str::find(triple, "i686") >= 0 ||
288+
str::find(triple, "i786") >= 0 {
289289
some(session::arch_x86)
290-
} else if str::contains(triple, "x86_64") {
290+
} else if str::find(triple, "x86_64") >= 0 {
291291
some(session::arch_x86_64)
292-
} else if str::contains(triple, "arm") ||
293-
str::contains(triple, "xscale") {
292+
} else if str::find(triple, "arm") >= 0 ||
293+
str::find(triple, "xscale") >= 0 {
294294
some(session::arch_arm)
295295
} else { none };
296296
}

trunk/src/comp/middle/shape.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ fn static_size_of_enum(cx: @crate_ctxt, t: ty::t)
666666
let max_size = 0u;
667667
let variants = ty::enum_variants(cx.tcx, tid);
668668
for variant: ty::variant_info in *variants {
669-
let tup_ty = simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
669+
let tup_ty = simplify_type(cx.tcx,
670+
ty::mk_tup(cx.tcx, variant.args));
670671
// Perform any type parameter substitutions.
671672

672673
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
@@ -776,29 +777,26 @@ fn dynamic_metrics(cx: @block_ctxt, t: ty::t) -> metrics {
776777
// to have (a) the same size as the type that was passed in; (b) to be non-
777778
// recursive. This is done by replacing all boxes in a type with boxed unit
778779
// types.
779-
fn simplify_type(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
780-
fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
780+
// This should reduce all pointers to some simple pointer type, to
781+
// ensure that we don't recurse endlessly when computing the size of a
782+
// nominal type that has pointers to itself in it.
783+
fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
784+
fn nilptr(tcx: ty::ctxt) -> ty::t {
785+
ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mut: ast::imm})
786+
}
787+
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
781788
alt ty::get(typ).struct {
782-
ty::ty_box(_) | ty::ty_opaque_box {
783-
ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx));
784-
}
785-
ty::ty_uniq(_) {
786-
ret ty::mk_imm_uniq(ccx.tcx, ty::mk_nil(ccx.tcx));
787-
}
788-
ty::ty_fn(_) {
789-
ret ty::mk_tup(ccx.tcx,
790-
[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
791-
ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx))]);
792-
}
789+
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) | ty::ty_vec(_) |
790+
ty::ty_ptr(_) { nilptr(tcx) }
791+
ty::ty_fn(_) { ty::mk_tup(tcx, [nilptr(tcx), nilptr(tcx)]) }
793792
ty::ty_res(_, sub, tps) {
794-
let sub1 = ty::substitute_type_params(ccx.tcx, tps, sub);
795-
ret ty::mk_tup(ccx.tcx,
796-
[ty::mk_int(ccx.tcx), simplify_type(ccx, sub1)]);
793+
let sub1 = ty::substitute_type_params(tcx, tps, sub);
794+
ty::mk_tup(tcx, [ty::mk_int(tcx), simplify_type(tcx, sub1)])
797795
}
798-
_ { ret typ; }
796+
_ { typ }
799797
}
800798
}
801-
ret ty::fold_ty(ccx.tcx, ty::fm_general(bind simplifier(ccx, _)), typ);
799+
ty::fold_ty(tcx, ty::fm_general(bind simplifier(tcx, _)), typ)
802800
}
803801

804802
// Given a tag type `ty`, returns the offset of the payload.

trunk/src/compiletest/errors.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ fn load_errors(testfile: str) -> [expected_error] {
2424

2525
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
2626
let error_tag = "//!";
27-
let idx;
28-
alt str::find_bytes(line, error_tag) {
29-
option::none { ret []; }
30-
option::some(nn) { idx = (nn as uint) + str::len_bytes(error_tag); }
31-
}
27+
let idx0 = str::find(line, error_tag);
28+
if idx0 < 0 { ret []; }
29+
let idx = (idx0 as uint) + str::len_bytes(error_tag);
3230

3331
// "//!^^^ kind msg" denotes a message expected
3432
// three lines above current line:

trunk/src/compiletest/header.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,18 @@ fn parse_pp_exact(line: str, testfile: str) -> option<str> {
100100
}
101101

102102
fn parse_name_directive(line: str, directive: str) -> bool {
103-
str::contains(line, directive)
103+
str::find(line, directive) >= 0
104104
}
105105

106106
fn parse_name_value_directive(line: str,
107107
directive: str) -> option<str> unsafe {
108108
let keycolon = directive + ":";
109-
alt str::find_bytes(line, keycolon) {
110-
option::some(colon) {
111-
let value =
112-
str::unsafe::slice_bytes(line,
113-
colon + str::len_bytes(keycolon),
114-
str::len_bytes(line));
115-
#debug("%s: %s", directive, value);
116-
option::some(value)
117-
}
118-
option::none { option::none }
119-
}
109+
if str::find(line, keycolon) >= 0 {
110+
let colon = str::find(line, keycolon) as uint;
111+
let value =
112+
str::unsafe::slice_bytes(line, colon + str::len_bytes(keycolon),
113+
str::len_bytes(line));
114+
#debug("%s: %s", directive, value);
115+
option::some(value)
116+
} else { option::none }
120117
}

trunk/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_error_patterns(props: test_props,
199199
let next_err_idx = 0u;
200200
let next_err_pat = props.error_patterns[next_err_idx];
201201
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
202-
if str::contains(line, next_err_pat) {
202+
if str::find(line, next_err_pat) > 0 {
203203
#debug("found error pattern %s", next_err_pat);
204204
next_err_idx += 1u;
205205
if next_err_idx == vec::len(props.error_patterns) {

trunk/src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn write_file(filename: str, content: str) {
1616
}
1717

1818
fn contains(haystack: str, needle: str) -> bool {
19-
str::contains(haystack, needle)
19+
str::find(haystack, needle) != -1
2020
}
2121

2222
fn find_rust_files(&files: [str], path: str) {

trunk/src/libcore/str.rs

Lines changed: 50 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export
7070
index,
7171
rindex,
7272
find,
73-
find_bytes,
7473
contains,
7574
starts_with,
7675
ends_with,
@@ -664,10 +663,9 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
664663
unsafe::slice_bytes(s, len_bytes(from), len_bytes(s)),
665664
from, to);
666665
} else {
667-
let idx;
668-
alt find_bytes(s, from) {
669-
option::some(x) { idx = x; }
670-
option::none { ret s; }
666+
let idx = find(s, from);
667+
if idx == -1 {
668+
ret s;
671669
}
672670
let before = unsafe::slice_bytes(s, 0u, idx as uint);
673671
let after = unsafe::slice_bytes(s, idx as uint + len_bytes(from),
@@ -876,62 +874,38 @@ fn rindex(ss: str, cc: char) -> option<uint> {
876874
ret option::none;
877875
}
878876

879-
//Function: find_bytes
880-
//
881-
// Find the char position of the first instance of one string
882-
// within another, or return option::none
883-
//
884-
// FIXME: Boyer-Moore should be significantly faster
885-
fn find_bytes(haystack: str, needle: str) -> option<uint> {
886-
let haystack_len = len_bytes(haystack);
887-
let needle_len = len_bytes(needle);
877+
/*
878+
Function: find
888879
889-
if needle_len == 0u { ret option::some(0u); }
890-
if needle_len > haystack_len { ret option::none; }
880+
Finds the index of the first matching substring.
881+
Returns -1 if `haystack` does not contain `needle`.
891882
892-
fn match_at(haystack: str, needle: str, ii: uint) -> bool {
893-
let jj = ii;
894-
for c: u8 in needle { if haystack[jj] != c { ret false; } jj += 1u; }
895-
ret true;
896-
}
897-
898-
let ii = 0u;
899-
while ii <= haystack_len - needle_len {
900-
if match_at(haystack, needle, ii) { ret option::some(ii); }
901-
ii += 1u;
902-
}
883+
Parameters:
903884
904-
ret option::none;
905-
}
885+
haystack - The string to look in
886+
needle - The string to look for
906887
907-
// Function: find
908-
//
909-
// Find the char position of the first instance of one string
910-
// within another, or return option::none
911-
fn find(haystack: str, needle: str) -> option<uint> {
912-
alt find_bytes(haystack, needle) {
913-
option::none { ret option::none; }
914-
option::some(nn) { ret option::some(b2c_pos(haystack, nn)); }
915-
}
916-
}
888+
Returns:
917889
918-
// Function: b2c_pos
919-
//
920-
// Convert a byte position into a char position
921-
// within a given string
922-
fn b2c_pos(ss: str, bpos: uint) -> uint {
923-
assert bpos == 0u || bpos < len_bytes(ss);
924-
925-
let ii = 0u;
926-
let cpos = 0u;
927-
928-
while ii < bpos {
929-
let sz = utf8_char_width(ss[ii]);
930-
ii += sz;
931-
cpos += 1u;
932-
}
890+
The index of the first occurance of `needle`, or -1 if not found.
933891
934-
ret cpos;
892+
FIXME: return an option<char position uint> instead
893+
*/
894+
fn find(haystack: str, needle: str) -> int {
895+
let haystack_len: int = len_bytes(haystack) as int;
896+
let needle_len: int = len_bytes(needle) as int;
897+
if needle_len == 0 { ret 0; }
898+
fn match_at(haystack: str, needle: str, i: int) -> bool {
899+
let j: int = i;
900+
for c: u8 in needle { if haystack[j] != c { ret false; } j += 1; }
901+
ret true;
902+
}
903+
let i: int = 0;
904+
while i <= haystack_len - needle_len {
905+
if match_at(haystack, needle, i) { ret i; }
906+
i += 1;
907+
}
908+
ret -1;
935909
}
936910

937911
/*
@@ -945,7 +919,7 @@ haystack - The string to look in
945919
needle - The string to look for
946920
*/
947921
fn contains(haystack: str, needle: str) -> bool {
948-
option::is_some(find_bytes(haystack, needle))
922+
0 <= find(haystack, needle)
949923
}
950924

951925
/*
@@ -958,12 +932,12 @@ Parameters:
958932
haystack - The string to look in
959933
needle - The string to look for
960934
*/
961-
fn starts_with(haystack: str, needle: str) -> bool unsafe {
962-
let haystack_len: uint = len_bytes(haystack);
963-
let needle_len: uint = len_bytes(needle);
935+
fn starts_with(haystack: str, needle: str) -> bool {
936+
let haystack_len: uint = len(haystack);
937+
let needle_len: uint = len(needle);
964938
if needle_len == 0u { ret true; }
965939
if needle_len > haystack_len { ret false; }
966-
ret eq(unsafe::slice_bytes(haystack, 0u, needle_len), needle);
940+
ret eq(substr(haystack, 0u, needle_len), needle);
967941
}
968942

969943
/*
@@ -1722,40 +1696,26 @@ mod tests {
17221696
assert [] == words("");
17231697
}
17241698

1725-
#[test]
1726-
fn test_find_bytes() {
1727-
// byte positions
1728-
assert (find_bytes("banana", "apple pie") == option::none);
1729-
assert (find_bytes("", "") == option::some(0u));
1730-
1731-
let data = "ประเทศไทย中华Việt Nam";
1732-
assert (find_bytes(data, "") == option::some(0u));
1733-
assert (find_bytes(data, "ประเ") == option::some( 0u));
1734-
assert (find_bytes(data, "ะเ") == option::some( 6u));
1735-
assert (find_bytes(data, "中华") == option::some(27u));
1736-
assert (find_bytes(data, "ไท华") == option::none);
1737-
}
1738-
17391699
#[test]
17401700
fn test_find() {
1741-
// char positions
1742-
assert (find("banana", "apple pie") == option::none);
1743-
assert (find("", "") == option::some(0u));
1744-
1745-
let data = "ประเทศไทย中华Việt Nam";
1746-
assert (find(data, "") == option::some(0u));
1747-
assert (find(data, "ประเ") == option::some(0u));
1748-
assert (find(data, "ะเ") == option::some(2u));
1749-
assert (find(data, "中华") == option::some(9u));
1750-
assert (find(data, "ไท华") == option::none);
1751-
}
1701+
fn t(haystack: str, needle: str, i: int) {
1702+
let j: int = find(haystack, needle);
1703+
log(debug, "searched for " + needle);
1704+
log(debug, j);
1705+
assert (i == j);
1706+
}
1707+
t("this is a simple", "is a", 5);
1708+
t("this is a simple", "is z", -1);
1709+
t("this is a simple", "", 0);
1710+
t("this is a simple", "simple", 10);
1711+
t("this", "simple", -1);
17521712

1753-
#[test]
1754-
fn test_b2c_pos() {
1713+
// FIXME: return option<char> position instead
17551714
let data = "ประเทศไทย中华Việt Nam";
1756-
assert 0u == b2c_pos(data, 0u);
1757-
assert 2u == b2c_pos(data, 6u);
1758-
assert 9u == b2c_pos(data, 27u);
1715+
assert (find(data, "ประเ") == 0);
1716+
assert (find(data, "ะเ") == 6); // byte position
1717+
assert (find(data, "中华") == 27); // byte position
1718+
assert (find(data, "ไท华") == -1);
17591719
}
17601720

17611721
#[test]

trunk/src/libstd/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn filter_tests(opts: test_opts,
258258

259259
fn filter_fn(test: test_desc, filter_str: str) ->
260260
option<test_desc> {
261-
if str::contains(test.name, filter_str) {
261+
if str::find(test.name, filter_str) >= 0 {
262262
ret option::some(test);
263263
} else { ret option::none; }
264264
}

0 commit comments

Comments
 (0)