/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
folly/FBString.h
fbstring
is a drop-in replacement for std::string
. The main benefit of fbstring
is significantly increased performance on virtually all important primitives. This is achieved by using a three-tiered storage strategy and by cooperating with the memory allocator. In particular, fbstring
is designed to detect use of jemalloc and cooperate with it to achieve significant improvements in speed and memory usage.
fbstring
supports 32- and 64-bit and little- and big-endian architectures.
Small strings (<= 23 chars) are stored in-situ without memory allocation.
Medium strings (24 - 255 chars) are stored in malloc-allocated memory and copied eagerly.
Large strings (> 255 chars) are stored in malloc-allocated memory and copied lazily.
100% compatible with std::string
.
Thread-safe reference counted copy-on-write for strings “large” strings (> 255 chars).
Uses malloc
instead of allocators.
Jemalloc-friendly. fbstring
automatically detects if application uses jemalloc and if so, significantly improves allocation strategy by using non-standard jemalloc extensions.
find()
is implemented using simplified Boyer-Moore algorithm. Casual tests indicate a 30x speed improvement over string::find()
for successful searches and a 1.5x speed improvement for failed searches.
Offers conversions to and from std::string
.