[Gmp-commit] /var/hg/gmp: C++: automatically turn c=(a+b)/2 into c=a+b; c/=2, ...
mercurial at gmplib.org
mercurial at gmplib.org
Sun May 15 22:04:15 CEST 2011
details: /var/hg/gmp/rev/c8c86b9ffe1f
changeset: 14184:c8c86b9ffe1f
user: Marc Glisse <marc.glisse at inria.fr>
date: Sun May 15 22:04:11 2011 +0200
description:
C++: automatically turn c=(a+b)/2 into c=a+b;c/=2, no need for a temporary.
diffstat:
ChangeLog | 4 +++-
gmpxx.h | 16 ++++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)
diffs (57 lines):
diff -r 047945898d48 -r c8c86b9ffe1f ChangeLog
--- a/ChangeLog Sun May 15 11:36:23 2011 +0200
+++ b/ChangeLog Sun May 15 22:04:11 2011 +0200
@@ -3,9 +3,11 @@
* gmpxx.h (operator<<): Dedup.
* tests/cxx/t-iostream.cc: Test on compound types.
+ * gmpxx.h (__gmp_binary_expr): Let things happen in place: c=(a+b)/2.
+
2011-05-10 Marc Glisse <marc.glisse at inria.fr>
- * gmpxx.h (__gmp_unary_expr): Let things happen in place.
+ * gmpxx.h (__gmp_unary_expr): Let things happen in place: c=-(a+b).
(operator>>): Clean the commenting out.
* tests/cxx/t-iostream.cc: New file.
* tests/cxx/Makefile.am: Added t-iostream.
diff -r 047945898d48 -r c8c86b9ffe1f gmpxx.h
--- a/gmpxx.h Sun May 15 11:36:23 2011 +0200
+++ b/gmpxx.h Sun May 15 22:04:11 2011 +0200
@@ -2181,14 +2181,14 @@
: expr(val1, val2) { }
void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
{
- __gmp_expr<T, T> temp(expr.val1);
- Op::eval(p, temp.__get_mp(), expr.val2);
+ expr.val1.eval(p);
+ Op::eval(p, p, expr.val2);
}
void eval(typename __gmp_resolve_expr<T>::ptr_type p,
mp_bitcnt_t prec) const
{
- __gmp_expr<T, T> temp(expr.val1, prec);
- Op::eval(p, temp.__get_mp(), expr.val2);
+ expr.val1.eval(p, prec);
+ Op::eval(p, p, expr.val2);
}
const val1_type & get_val1() const { return expr.val1; }
const val2_type & get_val2() const { return expr.val2; }
@@ -2208,14 +2208,14 @@
: expr(val1, val2) { }
void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
{
- __gmp_expr<T, T> temp(expr.val2);
- Op::eval(p, expr.val1, temp.__get_mp());
+ expr.val2.eval(p);
+ Op::eval(p, expr.val1, p);
}
void eval(typename __gmp_resolve_expr<T>::ptr_type p,
mp_bitcnt_t prec) const
{
- __gmp_expr<T, T> temp(expr.val2, prec);
- Op::eval(p, expr.val1, temp.__get_mp());
+ expr.val2.eval(p, prec);
+ Op::eval(p, expr.val1, p);
}
const val1_type & get_val1() const { return expr.val1; }
const val2_type & get_val2() const { return expr.val2; }
More information about the gmp-commit
mailing list