Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Enzo Cioppettini
ion
Commits
576182b4
Commit
576182b4
authored
7 years ago
by
Michael Aaron Murphy
Browse files
Options
Downloads
Patches
Plain Diff
Eliminate Heap Allocation w/ !* Designator
parent
079a2367
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shell/binary/designators.rs
+13
-3
13 additions, 3 deletions
src/shell/binary/designators.rs
with
13 additions
and
3 deletions
src/shell/binary/designators.rs
+
13
−
3
View file @
576182b4
...
...
@@ -106,9 +106,19 @@ pub(crate) fn expand_designators<'a>(shell: &Shell, cmd: &'a str) -> Cow<'a, str
fn
command
<
'a
>
(
text
:
&
'a
str
)
->
&
'a
str
{
ArgumentSplitter
::
new
(
text
)
.next
()
.unwrap_or
(
text
)
}
// TODO: do this without allocating a string.
fn
args
(
text
:
&
str
)
->
String
{
ArgumentSplitter
::
new
(
text
)
.skip
(
1
)
.collect
::
<
Vec
<&
str
>>
()
.join
(
" "
)
fn
args
(
text
:
&
str
)
->
&
str
{
let
bytes
=
text
.as_bytes
();
bytes
.iter
()
// Obtain position of the first space character,
.position
(|
&
x
|
x
==
b' '
)
// and then obtain the arguments to the command.
.and_then
(|
fp
|
bytes
[
fp
+
1
..
]
.iter
()
// Find the position of the first character in the first argument.
.position
(|
&
x
|
x
!=
b' '
)
// Then slice the argument string from the original command.
.map
(|
sp
|
&
text
[
fp
+
sp
+
1
..
]))
// Unwrap the arguments string if it exists, else return the original string.
.unwrap_or
(
text
)
}
fn
first_arg
<
'a
>
(
text
:
&
'a
str
)
->
&
'a
str
{
ArgumentSplitter
::
new
(
text
)
.nth
(
1
)
.unwrap_or
(
text
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment