Mailinglist Archive: yast-commit (819 mails)

< Previous Next >
[yast-commit] r54419 - /trunk/core/libycp/src/YCPBuiltinList.cc
  • From: aschnell@xxxxxxxxxxxxxxxx
  • Date: Wed, 07 Jan 2009 11:43:16 -0000
  • Message-id: <E1LKWoe-0004tR-4B@xxxxxxxxxxxxxxxx>
Author: aschnell
Date: Wed Jan 7 12:43:15 2009
New Revision: 54419

URL: http://svn.opensuse.org/viewcvs/yast?rev=54419&view=rev
Log:
- base reduce1 and reduce2 on reduce_helper

Modified:
trunk/core/libycp/src/YCPBuiltinList.cc

Modified: trunk/core/libycp/src/YCPBuiltinList.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCPBuiltinList.cc?rev=54419&r1=54418&r2=54419&view=diff
==============================================================================
--- trunk/core/libycp/src/YCPBuiltinList.cc (original)
+++ trunk/core/libycp/src/YCPBuiltinList.cc Wed Jan 7 12:43:15 2009
@@ -1104,6 +1104,44 @@


static YCPValue
+l_reduce_helper(const YCPSymbol &x, const YCPSymbol &y, const YCPValue
&initial,
+ const YCPList::const_iterator &first, const
YCPList::const_iterator &last,
+ const YCPCode &expr)
+{
+ SymbolEntryPtr xs = x->asEntry()->entry();
+ SymbolEntryPtr ys = y->asEntry()->entry();
+
+ YCPValue ret = initial;
+
+ for (YCPList::const_iterator it = first; it != last; ++it)
+ {
+ xs->setValue(ret);
+ ys->setValue(*it);
+
+ YCPValue tmp = expr->evaluate();
+ if (tmp.isNull())
+ {
+ ycp2error("Bad 'reduce' expression %s", expr->toString().c_str());
+ continue;
+ }
+ if (tmp->isVoid())
+ {
+ ycp2error("The expression for 'reduce' returned 'nil'");
+ continue;
+ }
+ if (tmp->isBreak())
+ {
+ break;
+ }
+
+ ret = tmp;
+ }
+
+ return ret;
+}
+
+
+static YCPValue
l_reduce1 (const YCPSymbol &x, const YCPSymbol &y, const YCPList &list, const
YCPCode &expr)
{
/**
@@ -1129,47 +1167,17 @@
* @usage list::reduce (integer x, integer y, [2, 4, 6], { return x > y ?
x : y; }) -> 6
*/

- if (list.isNull())
- {
- return YCPNull();
- }
-
- if (list->size() < 1)
+ if (list->isEmpty())
{
- ycp2error("Empty list for 'reduce'");
+ ycp2error("Empty list for 'reduce'");
return YCPNull();
}

- SymbolEntryPtr xs = x->asEntry()->entry();
- SymbolEntryPtr ys = y->asEntry()->entry();
-
- YCPValue ret = list->value(0);
-
- for (int i = 1; i < list->size(); i++)
- {
- xs->setValue(ret);
- ys->setValue(list->value(i));
+ const YCPList::const_iterator initial = list->begin();
+ const YCPList::const_iterator first = initial + 1;
+ const YCPList::const_iterator last = list->end();

- YCPValue tmp = expr->evaluate();
- if (tmp.isNull())
- {
- ycp2error("Bad 'reduce' expression %s", expr->toString().c_str());
- continue;
- }
- if (tmp->isVoid())
- {
- ycp2error("The expression for 'reduce' returned 'nil'");
- continue;
- }
- if (tmp->isBreak())
- {
- break;
- }
-
- ret = tmp;
- }
-
- return ret;
+ return l_reduce_helper(x, y, *initial, first, last, expr);
}


@@ -1186,7 +1194,7 @@
* @param list<flex2> list
* @param block<flex1> expression
* @return flex1
- *
+ *
* @description
* Apply expression cumulatively to the values of the list, from left to
* right, to reduce the list to a single value. See
@@ -1203,41 +1211,10 @@
* @usage list::reduce (term t, float f, `item(`id(`dummy)), [3.14, 2.71],
{ return add(t, tostring(f)); }) -> `item (`id (`dummy), "3.14", "2.71")
*/

- if (list.isNull())
- {
- return YCPNull();
- }
-
- SymbolEntryPtr xs = x->asEntry()->entry();
- SymbolEntryPtr ys = y->asEntry()->entry();
-
- YCPValue ret = initial;
+ const YCPList::const_iterator first = list->begin();
+ const YCPList::const_iterator last = list->end();

- for (int i = 0; i < list->size(); i++)
- {
- xs->setValue(ret);
- ys->setValue(list->value(i));
-
- YCPValue tmp = expr->evaluate();
- if (tmp.isNull())
- {
- ycp2error("Bad 'reduce' expression %s", expr->toString().c_str());
- continue;
- }
- if (tmp->isVoid())
- {
- ycp2error("The expression for 'reduce' returned 'nil'");
- continue;
- }
- if (tmp->isBreak())
- {
- break;
- }
-
- ret = tmp;
- }
-
- return ret;
+ return l_reduce_helper(x, y, initial, first, last, expr);
}



--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages