folly/folly/detail/SplitStringSimd.h

/*
 * 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.
 */

#pragma once

#include <string>
#include <vector>
#include <folly/Range.h>

namespace folly {

template <typename T, std::size_t M, typename P>
class small_vector;

template <typename T, typename Allocator>
class fbvector;

template <class Char>
class fbstring_core;

template <typename E, typename T, typename A, typename Storage>
class basic_fbstring;

namespace detail {

PredeclareFbString;

template <typename Container>
struct SimdSplitByCharImpl {};

// Different name to easier identify in the stack potential performance issues
template <typename Container>
struct SimdSplitByCharImplToStrings {};

isSimdSplitSupportedStringViewType;

isSimdSplitSupportedStringType;

template <typename>
struct SimdSplitByCharIsDefinedFor {};

SimdSplitByCharIsDefinedFor<std::vector<T>>;

SimdSplitByCharIsDefinedFor<folly::fbvector<T, A>>;

SimdSplitByCharIsDefinedFor<folly::small_vector<T, M, void>>;

template <typename Container>
std::enable_if_t<
    isSimdSplitSupportedStringViewType<typename Container::value_type>>
simdSplitByChar(
    char sep, folly::StringPiece what, Container& res, bool ignoreEmpty) {}

template <typename Container>
std::enable_if_t<isSimdSplitSupportedStringType<typename Container::value_type>>
simdSplitByChar(
    char sep, folly::StringPiece what, Container& res, bool ignoreEmpty) {}

// clang-format off
#define FOLLY_DETAIL_DECLARE_ALL_SIMD_SPLIT_OVERLOADS
// clang-format on

FOLLY_DETAIL_DECLARE_ALL_SIMD_SPLIT_OVERLOADS(folly::StringPiece)

FOLLY_DETAIL_DECLARE_ALL_SIMD_SPLIT_OVERLOADS(std::string_view)

extern template struct SimdSplitByCharImplToStrings<std::vector<std::string>>;
extern template struct SimdSplitByCharImplToStrings<
    std::vector<PredeclareFbString>>;
extern template struct SimdSplitByCharImplToStrings<
    fbvector<std::string, std::allocator<std::string>>>;
extern template struct SimdSplitByCharImplToStrings<
    fbvector<PredeclareFbString, std::allocator<PredeclareFbString>>>;

#undef FOLLY_DETAIL_DECLARE_ALL_SIMD_SPLIT_OVERLOADS

} // namespace detail
} // namespace folly