From b02d434889ac7e937aaf01b1e601c76aa119640e Mon Sep 17 00:00:00 2001 From: Andrew Krieger Date: Sun, 15 Oct 2017 21:30:56 -0700 Subject: [PATCH] constexpr estimateSpaceNeeded for string literals. Summary: Partially inspired by WillerZ's investigation into faster compiling StringPiece work, I thought this would be an easy drop in that short circuits some compilation logic (or possibly is strictly better, since the StringPiece conversion method isn't constexpr). Reviewed By: yfeldblum Differential Revision: D6059537 fbshipit-source-id: 072f56e58aa47db10b54825cac8a05dc035b295c --- folly/Conv.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/folly/Conv.h b/folly/Conv.h index be0d3d0d..ce30765c 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -408,6 +408,11 @@ estimateSpaceNeeded(T) { return 1; } +template +constexpr size_t estimateSpaceNeeded(const char (&)[N]) { + return N; +} + /** * Everything implicitly convertible to const char* gets appended. */ -- 2.34.1