folly: Bits: restore type of bitOffset_ to shorter "unsigned int"
authorJim Meyering <meyering@fb.com>
Sat, 10 Jan 2015 06:28:00 +0000 (22:28 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:11:24 +0000 (13:11 -0800)
Summary:
My initial change to avoid the -Wsign-compare error neglected
the fact that the difference of two unsigned types is also
unsigned. That broke some unicorn tests, as seen in D1776343,
which worked around the problem by changing the type of
bitOffset_ like this: s/unsigned int/size_t.

The real problem lay in the distance_to function, which computed
the signed difference of two bitOffset_ values.
To work properly with the narrower unsigned type,
we could either first widen each operand to ssize_t
before computing their parenthesized difference, or
(as Philip suggested and I prefer), just drop the
parentheses and let the signedness of the preceding
operands ensure that each successive intermediate
result is also signed.

Test Plan:
Choose one of the failing tests, and ensure it now passes:

fbconfig -r unicorn/diskindex4/test:doc_map_test
fbmake runtests

Also run all unicorn tests, for good measure (still waiting):
fbconfig -r unicorn && fbmake runtests

Reviewed By: philipp@fb.com, andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1776624

Tasks: 5941250

Signature: t1:1776624:1420872874:b1ea8a3f23f21269aa65cbe1647e86a8f622a710

Blame Revision: D1770613

folly/Bits.h

index a93be1b6c365224ae08aea002bce3c972b043a8c..2136cfadb58da0b97fee2164a0ed459d3ff9fda7 100644 (file)
@@ -522,10 +522,10 @@ class BitIterator
   ssize_t distance_to(const BitIterator& other) const {
     return
       (other.base_reference() - this->base_reference()) * bitsPerBlock() +
-      (other.bitOffset_ - bitOffset_);
+      other.bitOffset_ - bitOffset_;
   }
 
-  size_t bitOffset_;
+  unsigned int bitOffset_;
 };
 
 /**