mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-27 14:14:11 +00:00
libclamav/matcher-ac.c: micro-optimization (bb#843), thanks to Edwin
git-svn: trunk@4334
This commit is contained in:
parent
d6e1ef1611
commit
a305a2616a
2 changed files with 36 additions and 2 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Nov 4 20:50:45 CET 2008 (tk)
|
||||||
|
---------------------------------
|
||||||
|
* libclamav/matcher-ac.c: micro-optimization (bb#843), thanks to Edwin
|
||||||
|
|
||||||
Tue Nov 4 20:47:14 CET 2008 (acab)
|
Tue Nov 4 20:47:14 CET 2008 (acab)
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
* libclamav: mempool de-uglify
|
* libclamav: mempool de-uglify
|
||||||
|
|
|
||||||
|
|
@ -258,8 +258,13 @@ static int ac_maketrans(struct cli_matcher *root)
|
||||||
}
|
}
|
||||||
|
|
||||||
while((node = bfs_dequeue(&bfs, &bfs_last))) {
|
while((node = bfs_dequeue(&bfs, &bfs_last))) {
|
||||||
if(node->leaf)
|
if(node->leaf) {
|
||||||
|
struct cli_ac_node *failtarget = node->fail;
|
||||||
|
while(failtarget->leaf)
|
||||||
|
failtarget = failtarget->fail;
|
||||||
|
node->fail = failtarget;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < 256; i++) {
|
for(i = 0; i < 256; i++) {
|
||||||
child = node->trans[i];
|
child = node->trans[i];
|
||||||
|
|
@ -289,6 +294,31 @@ static int ac_maketrans(struct cli_matcher *root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bfs = bfs_last = NULL;
|
||||||
|
for(i = 0; i < 256; i++) {
|
||||||
|
node = ac_root->trans[i];
|
||||||
|
if(node != ac_root) {
|
||||||
|
if((ret = bfs_enqueue(&bfs, &bfs_last, node)))
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while((node = bfs_dequeue(&bfs, &bfs_last))) {
|
||||||
|
if(node->leaf)
|
||||||
|
continue;
|
||||||
|
for(i = 0; i < 256; i++) {
|
||||||
|
child = node->trans[i];
|
||||||
|
if(!child) {
|
||||||
|
struct cli_ac_node *failtarget = node->fail;
|
||||||
|
while(failtarget->leaf || !failtarget->trans[i])
|
||||||
|
failtarget = failtarget->fail;
|
||||||
|
node->trans[i] = failtarget->trans[i];
|
||||||
|
} else {
|
||||||
|
if((ret = bfs_enqueue(&bfs, &bfs_last, child)) != 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CL_SUCCESS;
|
return CL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -875,7 +905,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
|
||||||
|
|
||||||
for(i = 0; i < length; i++) {
|
for(i = 0; i < length; i++) {
|
||||||
|
|
||||||
while(current->leaf || !current->trans[buffer[i]])
|
if(current->leaf)
|
||||||
current = current->fail;
|
current = current->fail;
|
||||||
|
|
||||||
current = current->trans[buffer[i]];
|
current = current->trans[buffer[i]];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue