From 8416b4e42cc73fb64b18da6ced77a1f945ed5fee Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 23 Aug 2017 19:02:11 -0700 Subject: [PATCH] Add default parameter to StringRef to allow null termination on lengthed strings. (#27) --- src/main/native/include/llvm/StringRef.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/native/include/llvm/StringRef.h b/src/main/native/include/llvm/StringRef.h index c147534a81..b58ebbc6b6 100644 --- a/src/main/native/include/llvm/StringRef.h +++ b/src/main/native/include/llvm/StringRef.h @@ -90,14 +90,15 @@ namespace llvm { } /// Construct a string ref from a pointer and length. - /*implicit*/ StringRef(const char *data, size_t length) + /*implicit*/ StringRef(const char *data, size_t length, bool isNullTerminated = false) : Data(data), Length(length) { assert((data || length == 0) && "StringRef cannot be built from a NULL argument with non-null length"); // Require length to not use MSB of size assert(Length < ~((size_t)1 << (sizeof(size_t) * 8 - 1))); - // If passed an explicit length, we are not null terminated - set_null_terminated(false); + // If passed an explicit length, use the parameter + // Default to false (not null) to match previous behavior. + set_null_terminated(isNullTerminated); } /// Construct a string ref from an std::string. @@ -143,8 +144,8 @@ namespace llvm { bool empty() const { return size() == 0; } /// size - Get the string size. - size_t size() const { - return Length & ~((size_t)1 << (sizeof(size_t) * 8 - 1)); + size_t size() const { + return Length & ~((size_t)1 << (sizeof(size_t) * 8 - 1)); } /// is_null_terminated - Get if the string is guaranteed null terminated