about summary refs log tree commit diff
path: root/src/libregex
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2014-08-06 20:48:25 -0700
committerBrian Anderson <banderson@mozilla.com>2014-08-13 11:30:15 -0700
commita4b354ca0258b4914b6e6b64b0143a8aec861fa0 (patch)
tree4054b1c1f9b69e42bcd90724b085998062a7dfcd /src/libregex
parent76d46af6d405ac29d2d508705eacdcffad63e4c1 (diff)
downloadrust-a4b354ca0258b4914b6e6b64b0143a8aec861fa0.tar.gz
rust-a4b354ca0258b4914b6e6b64b0143a8aec861fa0.zip
core: Add binary_search and binary_search_elem methods to slices.
These are like the existing bsearch methods but if the search fails,
it returns the next insertion point.

The new `binary_search` returns a `BinarySearchResult` that is either
`Found` or `NotFound`. For convenience, the `found` and `not_found`
methods convert to `Option`, ala `Result`.

Deprecate bsearch and bsearch_elem.
Diffstat (limited to 'src/libregex')
-rw-r--r--src/libregex/vm.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs
index 118c2f7a3ce..6bf3e149066 100644
--- a/src/libregex/vm.rs
+++ b/src/libregex/vm.rs
@@ -35,6 +35,7 @@
 
 use std::cmp;
 use std::mem;
+use std::slice;
 use std::slice::MutableSlice;
 use compile::{
     Program,
@@ -222,8 +223,8 @@ impl<'r, 't> Nfa<'r, 't> {
                     let negate = flags & FLAG_NEGATED > 0;
                     let casei = flags & FLAG_NOCASE > 0;
                     let found = ranges.as_slice();
-                    let found = found.bsearch(|&rc| class_cmp(casei, c, rc));
-                    let found = found.is_some();
+                    let found = found.binary_search(|&rc| class_cmp(casei, c, rc))
+                        .found().is_some();
                     if found ^ negate {
                         self.add(nlist, pc+1, caps);
                     }
@@ -513,7 +514,7 @@ pub fn is_word(c: Option<char>) -> bool {
     // Try the common ASCII case before invoking binary search.
     match c {
         '_' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' => true,
-        _ => PERLW.bsearch(|&(start, end)| {
+        _ => PERLW.binary_search(|&(start, end)| {
             if c >= start && c <= end {
                 Equal
             } else if start > c {
@@ -521,7 +522,7 @@ pub fn is_word(c: Option<char>) -> bool {
             } else {
                 Less
             }
-        }).is_some()
+        }).found().is_some()
     }
 }