Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ff55725a
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff55725a
编写于
1月 05, 2018
作者:
M
Manish Goregaokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make double ended string searchers use dependent fingers (fixes #47175)
上级
dd582ac3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
6 deletion
+10
-6
src/libcore/str/pattern.rs
src/libcore/str/pattern.rs
+10
-6
未找到文件。
src/libcore/str/pattern.rs
浏览文件 @
ff55725a
...
...
@@ -284,7 +284,7 @@ fn haystack(&self) -> &'a str {
#[inline]
fn
next
(
&
mut
self
)
->
SearchStep
{
let
old_finger
=
self
.finger
;
let
slice
=
unsafe
{
self
.haystack
.get_unchecked
(
old_finger
..
self
.
haystack
.len
()
)
};
let
slice
=
unsafe
{
self
.haystack
.get_unchecked
(
old_finger
..
self
.
finger_back
)
};
let
mut
iter
=
slice
.chars
();
let
old_len
=
iter
.iter
.len
();
if
let
Some
(
ch
)
=
iter
.next
()
{
...
...
@@ -304,7 +304,8 @@ fn next(&mut self) -> SearchStep {
fn
next_match
(
&
mut
self
)
->
Option
<
(
usize
,
usize
)
>
{
loop
{
// get the haystack after the last character found
let
bytes
=
if
let
Some
(
slice
)
=
self
.haystack
.as_bytes
()
.get
(
self
.finger
..
)
{
let
bytes
=
if
let
Some
(
slice
)
=
self
.haystack
.as_bytes
()
.get
(
self
.finger
..
self
.finger_back
)
{
slice
}
else
{
return
None
;
...
...
@@ -340,7 +341,7 @@ fn next_match(&mut self) -> Option<(usize, usize)> {
}
}
else
{
// found nothing, exit
self
.finger
=
self
.
haystack
.len
()
;
self
.finger
=
self
.
finger_back
;
return
None
;
}
}
...
...
@@ -353,7 +354,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
#[inline]
fn
next_back
(
&
mut
self
)
->
SearchStep
{
let
old_finger
=
self
.finger_back
;
let
slice
=
unsafe
{
self
.haystack
.slice_unchecked
(
0
,
old_finger
)
};
let
slice
=
unsafe
{
self
.haystack
.slice_unchecked
(
self
.finger
,
old_finger
)
};
let
mut
iter
=
slice
.chars
();
let
old_len
=
iter
.iter
.len
();
if
let
Some
(
ch
)
=
iter
.next_back
()
{
...
...
@@ -374,7 +375,7 @@ fn next_match_back(&mut self) -> Option<(usize, usize)> {
let
haystack
=
self
.haystack
.as_bytes
();
loop
{
// get the haystack up to but not including the last character searched
let
bytes
=
if
let
Some
(
slice
)
=
haystack
.get
(
..
self
.finger_back
)
{
let
bytes
=
if
let
Some
(
slice
)
=
haystack
.get
(
self
.finger
..
self
.finger_back
)
{
slice
}
else
{
return
None
;
...
...
@@ -382,6 +383,9 @@ fn next_match_back(&mut self) -> Option<(usize, usize)> {
// the last byte of the utf8 encoded needle
let
last_byte
=
unsafe
{
*
self
.utf8_encoded
.get_unchecked
(
self
.utf8_size
-
1
)
};
if
let
Some
(
index
)
=
memchr
::
memrchr
(
last_byte
,
bytes
)
{
// we searched a slice that was offset by self.finger,
// add self.finger to recoup the original index
let
index
=
self
.finger
+
index
;
// memrchr will return the index of the byte we wish to
// find. In case of an ASCII character, this is indeed
// were we wish our new finger to be ("after" the found
...
...
@@ -412,7 +416,7 @@ fn next_match_back(&mut self) -> Option<(usize, usize)> {
// found the last byte when searching in reverse.
self
.finger_back
=
index
;
}
else
{
self
.finger_back
=
0
;
self
.finger_back
=
self
.finger
;
// found nothing, exit
return
None
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录