Summary: Normally I would use the folly::to<> function, but it would cause a circular dependency, so I just added a static cast
Test Plan: Ran on iOS and ran the folly tests
Reviewed By: seanc@fb.com
Subscribers: lucian, mpawlowski, marcelo, tudorb, aalexandre, seanc, folly-diffs@
FB internal diff:
D1806632
Signature: t1:
1806632:
1422416646:
b8104f18f90eb7457f2f358428f2bd800f8f1db5
const size_type osize = o.size();
const size_type msize = std::min(tsize, osize);
int r = traits_type::compare(data(), o.data(), msize);
- if (r == 0) r = tsize - osize;
+ if (r == 0 && tsize != osize) {
+ // We check the signed bit of the subtraction and bit shift it
+ // to produce either 0 or 2. The subtraction yields the
+ // comparison values of either -1 or 1.
+ r = (static_cast<int>(
+ (osize - tsize) >> (CHAR_BIT * sizeof(size_t) - 1)) << 1) - 1;
+ }
return r;
}