diff --git a/eden/fs/utils/Memory.cpp b/eden/fs/utils/Memory.cpp deleted file mode 100644 index ebd4da4dcf..0000000000 --- a/eden/fs/utils/Memory.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2019-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - */ -#include "eden/fs/utils/Memory.h" -#include -#include -#include - -namespace facebook { -namespace eden { -size_t estimateIndirectMemoryUsage(const std::string& path) { - size_t length = path.length(); -#ifdef _LIBCPP_VERSION - constexpr size_t kStdStringSsoLength = sizeof(std::string) - 2; -#elif defined(__GLIBCXX__) || defined(__GLIBCPP__) - constexpr size_t kStdStringSsoLength = (sizeof(std::string) >> 1) - 1; -#else - constexpr size_t kStdStringSsoLength = 0; - NOT_IMPLEMENTED(); -#endif - if (length <= kStdStringSsoLength) { - return 0; - } else { - return folly::goodMallocSize(path.capacity()); - } -} - -size_t estimateIndirectMemoryUsage(const folly::fbstring& path) { - size_t length = path.length(); - constexpr size_t kFbStringSsoLength = 23; - if (length <= kFbStringSsoLength) { - return 0; - } else { - return folly::goodMallocSize(path.capacity()); - } -} -} // namespace eden -} // namespace facebook diff --git a/eden/fs/utils/Memory.h b/eden/fs/utils/Memory.h index 13481ad7cb..a17238e5f0 100644 --- a/eden/fs/utils/Memory.h +++ b/eden/fs/utils/Memory.h @@ -13,7 +13,21 @@ namespace facebook { namespace eden { -size_t estimateIndirectMemoryUsage(const std::string& path); -size_t estimateIndirectMemoryUsage(const folly::fbstring& path); +template +bool isStringStorageEmbedded(const StringType& t) { + const void* tbegin = &t; + const void* tend = &t + 1; + return std::less_equal{}(tbegin, t.data()) && + std::less{}(t.data(), tend); +} + +template +size_t estimateIndirectMemoryUsage(const StringType& s) { + if (isStringStorageEmbedded(s)) { + return 0; + } else { + return folly::goodMallocSize(s.capacity()); + } +} } // namespace eden } // namespace facebook