arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1517: Remove unnecessary temporary in DecimalUtil::ToString function
Date Sun, 10 Sep 2017 17:59:54 GMT
Repository: arrow
Updated Branches:
  refs/heads/master a534e5d53 -> 840b68744


ARROW-1517: Remove unnecessary temporary in DecimalUtil::ToString function

Author: Phillip Cloud <cpcloud@gmail.com>

Closes #1082 from cpcloud/ARROW-1517 and squashes the following commits:

49e30594 [Phillip Cloud] ARROW-1517: Remove unnecessary temporary in DecimalUtil::ToString
function


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/840b6874
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/840b6874
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/840b6874

Branch: refs/heads/master
Commit: 840b68744ac65c3e151bbc03f0e195fce2bb0f30
Parents: a534e5d
Author: Phillip Cloud <cpcloud@gmail.com>
Authored: Sun Sep 10 13:59:49 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Sun Sep 10 13:59:49 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/util/decimal.cc | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/840b6874/cpp/src/arrow/util/decimal.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc
index 3e17bf6..7dd5807 100644
--- a/cpp/src/arrow/util/decimal.cc
+++ b/cpp/src/arrow/util/decimal.cc
@@ -153,25 +153,24 @@ Status FromString(const std::string& s, Int128* out, int* precision,
int* scale)
 }
 
 std::string ToString(const Int128& decimal_value, int precision, int scale) {
-  Int128 value(decimal_value);
+  const bool is_negative = decimal_value < 0;
 
   // Decimal values are sent to clients as strings so in the interest of
   // speed the string will be created without the using stringstream with the
   // whole/fractional_part().
   size_t last_char_idx = precision + (scale > 0)  // Add a space for decimal place
                          + (scale == precision)   // Add a space for leading 0
-                         + (value < 0);           // Add a space for negative sign
+                         + is_negative;           // Add a space for negative sign
   std::string str(last_char_idx, '0');
 
   // Start filling in the values in reverse order by taking the last digit
   // of the value. Use a positive value and worry about the sign later. At this
   // point the last_char_idx points to the string terminator.
-  Int128 remaining_value(value);
+  Int128 remaining_value(decimal_value);
 
-  size_t first_digit_idx = 0;
-  if (value < 0) {
-    remaining_value = -value;
-    first_digit_idx = 1;
+  const auto first_digit_idx = static_cast<size_t>(is_negative);
+  if (is_negative) {
+    remaining_value.Negate();
   }
 
   if (scale > 0) {
@@ -199,7 +198,7 @@ std::string ToString(const Int128& decimal_value, int precision, int
scale) {
     // For safety, enforce string length independent of remaining_value.
   } while (last_char_idx > first_digit_idx);
 
-  if (value < 0) {
+  if (is_negative) {
     str[0] = '-';
   }
 


Mime
View raw message