From: Nicholas Ormrod Date: Thu, 12 Jun 2014 00:34:12 +0000 (-0700) Subject: static-ify FBString asserts X-Git-Tag: v0.22.0~511 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d6a1e277540b68ac69c242603c575564f388074c;p=folly.git static-ify FBString asserts Summary: Some asserts could be static_asserts. Make it so! Test Plan: fbconfig -r folly && fbmke opt && fbmake runtests_opt Reviewed By: lucian@fb.com Subscribers: folly@lists, sdwilsh, njormrod FB internal diff: D1378670 --- diff --git a/folly/FBString.h b/folly/FBString.h index 6bb78d01..424431f9 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -339,9 +339,12 @@ public: assert(&rhs != this); // Simplest case first: small strings are bitblitted if (rhs.category() == isSmall) { - assert(offsetof(MediumLarge, data_) == 0); - assert(offsetof(MediumLarge, size_) == sizeof(ml_.data_)); - assert(offsetof(MediumLarge, capacity_) == 2 * sizeof(ml_.data_)); + static_assert(offsetof(MediumLarge, data_) == 0, + "fbstring layout failure"); + static_assert(offsetof(MediumLarge, size_) == sizeof(ml_.data_), + "fbstring layout failure"); + static_assert(offsetof(MediumLarge, capacity_) == 2 * sizeof(ml_.data_), + "fbstring layout failure"); const size_t size = rhs.smallSize(); if (size == 0) { ml_.capacity_ = rhs.ml_.capacity_; @@ -400,10 +403,13 @@ public: // Simplest case first: small strings are bitblitted if (size <= maxSmallSize) { // Layout is: Char* data_, size_t size_, size_t capacity_ - /*static_*/assert(sizeof(*this) == sizeof(Char*) + 2 * sizeof(size_t)); - /*static_*/assert(sizeof(Char*) == sizeof(size_t)); + static_assert(sizeof(*this) == sizeof(Char*) + 2 * sizeof(size_t), + "fbstring has unexpected size"); + static_assert(sizeof(Char*) == sizeof(size_t), + "fbstring size assumption violation"); // sizeof(size_t) must be a power of 2 - /*static_*/assert((sizeof(size_t) & (sizeof(size_t) - 1)) == 0); + static_assert((sizeof(size_t) & (sizeof(size_t) - 1)) == 0, + "fbstring size assumption violation"); // If data is aligned, use fast word-wise copying. Otherwise, // use conservative memcpy.