From 2d404b3ab42c63027268c52fa50db590831ce987 Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(win7-laptop)> Date: Fri, 3 Dec 2010 22:02:18 +0100 Subject: [PATCH] Reshuffling code a bit for some optimization. --- libwccl/ops/functions/bool/iteration.cpp | 48 +++++++++++++----------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libwccl/ops/functions/bool/iteration.cpp b/libwccl/ops/functions/bool/iteration.cpp index 86707bf..b900d3c 100644 --- a/libwccl/ops/functions/bool/iteration.cpp +++ b/libwccl/ops/functions/bool/iteration.cpp @@ -28,30 +28,34 @@ std::string Iteration::to_raw_string() const Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context) const { - const boost::shared_ptr<const Position>& range_begin = left_pos_expr_->apply(context); - const boost::shared_ptr<const Position>& range_end = right_pos_expr_->apply(context); - const boost::shared_ptr<Position>& iter_var = context.variables()->get_fast(iter_var_acc_); - + const boost::shared_ptr<Position>& iter_var = + context.variables()->get_fast(iter_var_acc_); const SentenceContext& sc = context.sentence_context(); - // Get absolute values for left and right extremes of the range - int left = sc.get_abs_position(*range_begin); - int right = sc.get_abs_position(*range_end); // Proceed only if range extremes are not "nowhere". - if (left != Position::Nowhere && right != Position::Nowhere) { - // Trim range to sentence boundaries - if (left < 0) { - left = 0; - } - if (right >= sc.size()) { - right = sc.size() - 1; - } - // Proceed only if range isn't empty - if (left <= right) { - // Change range from absolute to relative and iterate - left -= sc.get_position(); - right -= sc.get_position(); - if (iterate(left, right, *iter_var, context)) { - return Predicate::True(context); + const boost::shared_ptr<const Position>& range_left = + left_pos_expr_->apply(context); + if (range_left->get_value() != Position::Nowhere) { + const boost::shared_ptr<const Position>& range_right = + right_pos_expr_->apply(context); + if (range_right->get_value() != Position::Nowhere) { + // Get absolute values for left and right extremes of the range. + int right = sc.get_abs_position(*range_end); + int left = sc.get_abs_position(*range_begin); + // Trim range to sentence boundaries + if (left < 0) { + left = 0; + } + if (right >= sc.size()) { + right = sc.size() - 1; + } + // Proceed only if range isn't empty + if (left <= right) { + // Change range from absolute to relative and iterate + left -= sc.get_position(); + right -= sc.get_position(); + if (iterate(left, right, *iter_var, context)) { + return Predicate::True(context); + } } } } -- GitLab