diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-02-18 23:55:25 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-02-18 23:55:25 -0800 |
commit | c570556b697cb30829b2cac2d1c5fd86d501022e (patch) | |
tree | 52ed9e5152315f99af40b7d4d97b5811aa05109a /058shape_shifting_container.cc | |
parent | e8a5f07843d768829b825033b3e7839493ec374e (diff) | |
download | mu-c570556b697cb30829b2cac2d1c5fd86d501022e.tar.gz |
2675
Make nth_type non-recursive in advance of hoisting the call into the caller.
Diffstat (limited to '058shape_shifting_container.cc')
-rw-r--r-- | 058shape_shifting_container.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/058shape_shifting_container.cc b/058shape_shifting_container.cc index 7b11a61e..6ad33fd6 100644 --- a/058shape_shifting_container.cc +++ b/058shape_shifting_container.cc @@ -396,20 +396,18 @@ void test_replace_middle_type_ingredient_with_multiple() { const type_tree* nth_type(const type_tree* base, long long int n) { assert(n >= 0); - if (n == 0) { - if (base && base->left) return base->left; - return base; - } - return nth_type(base->right, n-1); + for (; n > 0; --n) + base = base->right; + if (base && base->left) return base->left; + return base; } const string_tree* nth_type_name(const string_tree* base, long long int n) { assert(n >= 0); - if (n == 0) { - if (base && base->left) return base->left; - return base; - } - return nth_type_name(base->right, n-1); + for (; n > 0; --n) + base = base->right; + if (base && base->left) return base->left; + return base; } bool has_nth_type(const type_tree* base, long long int n) { |