diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-01-13 16:05:13 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-01-22 13:50:55 +0000 |
commit | 05242bb1d3badf5e71b2e5d6464dfbd53b3b39b3 (patch) | |
tree | 4c98c248b9538977ac9eeafc7dc3ab7a7f22d1c4 | |
parent | 5fb234f599e95d3a88d4a8f50847bd11f2a64256 (diff) | |
download | mupdf-05242bb1d3badf5e71b2e5d6464dfbd53b3b39b3.tar.xz |
Make fz_tree_lookup iterative rather than recursive.
-rw-r--r-- | source/fitz/tree.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/fitz/tree.c b/source/fitz/tree.c index dd5edc23..ca94a45b 100644 --- a/source/fitz/tree.c +++ b/source/fitz/tree.c @@ -24,15 +24,18 @@ static fz_tree *fz_tree_new_node(fz_context *ctx, const char *key, void *value) void *fz_tree_lookup(fz_context *ctx, fz_tree *node, const char *key) { - if (node && node != &sentinel) + if (node) { - int c = strcmp(key, node->key); - if (c == 0) - return node->value; - else if (c < 0) - return fz_tree_lookup(ctx, node->left, key); - else - return fz_tree_lookup(ctx, node->right, key); + while (node != &sentinel) + { + int c = strcmp(key, node->key); + if (c == 0) + return node->value; + else if (c < 0) + node = node->left; + else + node = node->right; + } } return NULL; } |