Skip to content

Commit

Permalink
Minor optimisation of grep.c
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin authored and radare committed Oct 23, 2013
1 parent 1b690e5 commit d1aaa61
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libr/cons/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ R_API void r_cons_grep(const char *str) {
case '?': str++; cons->grep.counter = 1;
if (*str=='?') {
r_cons_grep_help ();
str = "THIS\x01IS\x02A\x03HACK\x04:D";
return;
}
break;
default: goto while_end;
Expand Down Expand Up @@ -195,9 +195,11 @@ R_API int r_cons_grep_line(char *buf, int len) {
if (cons->grep.begin)
hit = (p == in)? 1: 0;
else hit = !cons->grep.neg;
// TODO: optimize this strlen
if (cons->grep.end && (strlen (cons->grep.strings[i]) != strlen (p)))
hit = 0;
if (cons->grep.end){
for (j=0; cons->grep.strings[i][j] && p[j]; j++);
if (!(cons->grep.strings[i][j] || p[j]))
hit = 0;
}
if (!cons->grep.amp)
break;
}
Expand All @@ -222,7 +224,7 @@ R_API int r_cons_grep_line(char *buf, int len) {
outlen += toklen+1;
}
} else {
if (strlen (out) == 0) {
if (!(*out)) {
free (in);
free (out);
return -1;
Expand Down

0 comments on commit d1aaa61

Please sign in to comment.