Small optimization in yr_re_ast_extract_literal.
@@ -411,7 +411,6 @@ SIZED_STRING* yr_re_ast_extract_literal(
RE_NODE* node = re_ast->root_node;
int i, length = 0;
- char tmp;
while (node != NULL)
{
@@ -435,26 +434,20 @@ SIZED_STRING* yr_re_ast_extract_literal(
if (string == NULL)
return NULL;
- string->length = 0;
-
+ string->length = length;
node = re_ast->root_node;
- while (node->type == RE_NODE_CONCAT)
+ // The root node is the end of the string. So let's fill it up backwards.
+ for (i = length - 1; i > 0; i--)
{
- string->c_string[string->length++] = node->right->value;
+ string->c_string[i] = node->right->value;
node = node->left;
}
- string->c_string[string->length++] = node->value;
-
- // The string ends up reversed. Reverse it back to its original value.
+ if (length > 0)
+ string->c_string[0] = node->value;
- for (i = 0; i < length / 2; i++)
- {
- tmp = string->c_string[i];
- string->c_string[i] = string->c_string[length - i - 1];
- string->c_string[length - i - 1] = tmp;
- }
+ assert(node == NULL || node->type == RE_NODE_LITERAL);
return string;
}
