-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of single-character string splitting.
Helps #661.
- Loading branch information
1 parent
96c5328
commit 6bc8a03
Showing
1 changed file
with
4 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6bc8a03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think strwidth is the right function here; probably strlen.
6bc8a03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a second to remember why I used
strwidth
: I wanted to only call the single character version ifstrlen(x)==1
andx[1]
is an ASCII character. I realize now that testing those together is better than usingstrwidth
, which will scan the entire string needlessly. Even better would be something likestrstr
, except that it doesn't handle NULs correctly. Probably best to usememchr
to find the first character and then just use a look to check if the rest of the string matches.6bc8a03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strwidth
doesn't do that; it gives the number of columns needed to display the string.6bc8a03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah. That's also true.
length(x) == 1
would be both faster and actually correct.