Use memchr in FindToken implementation.

This commit is contained in:
Ivan Enderlin 2017-05-10 11:41:15 +02:00
parent e88b652a4b
commit 834d4428d8
No known key found for this signature in database
GPG Key ID: 461F31FCE31F4AAD
3 changed files with 8 additions and 8 deletions

View File

@ -38,6 +38,9 @@ optional = true
version = "^0.2.2"
optional = true
[dependencies.memchr]
version = "^1.0.1"
#[dev-dependencies.bytes]
#git = "https://github.com/carllerche/bytes"
#rev = "a7d38e29"

View File

@ -99,6 +99,7 @@ extern crate collections;
extern crate regex;
#[cfg(feature = "regexp_macros")]
#[macro_use] extern crate lazy_static;
extern crate memchr;
#[cfg(feature = "nightly")]
extern crate test;

View File

@ -9,6 +9,8 @@ use std::str::CharIndices;
use std::str::FromStr;
use std::str::from_utf8;
use memchr::memchr;
/// abstract method to calculate the input length
pub trait InputLength {
@ -404,10 +406,7 @@ pub trait FindToken<T> {
impl<'a> FindToken<&'a[u8]> for u8 {
fn find_token(&self, input: &[u8]) -> bool {
for &i in input.iter() {
if *self == i { return true }
}
false
memchr(*self, input).is_some()
}
}
@ -419,10 +418,7 @@ impl<'a> FindToken<&'a str> for u8 {
impl<'a,'b> FindToken<&'a[u8]> for &'b u8 {
fn find_token(&self, input: &[u8]) -> bool {
for &i in input.iter() {
if **self == i { return true }
}
false
memchr(**self, input).is_some()
}
}