Summary: When internal cpp modernizer attempts to format rocksdb code, it will replace macro `ROCKSDB_NAMESPACE` with its default definition `rocksdb` when collapsing nested namespace. We filed a feedback for the tool T180254030 and the team filed a bug for this: https://github.com/llvm/llvm-project/issues/83452. At the same time, they suggested us to run the modernizer tool ourselves so future auto codemod attempts will be smaller. This diff contains: Running `xplat/scripts/codemod_service/cpp_modernizer.sh` in fbcode/internal_repo_rocksdb/repo (excluding some directories in utilities/transactions/lock/range/range_tree/lib that has a non meta copyright comment) without swapping out the namespace macro `ROCKSDB_NAMESPACE` Followed by RocksDB's own `make format` Pull Request resolved: https://github.com/facebook/rocksdb/pull/12398 Test Plan: Auto tests Reviewed By: hx235 Differential Revision: D54382532 Pulled By: jowlyzhang fbshipit-source-id: e7d5b40f9b113b60e5a503558c181f080b9d02fa
103 lines
2.8 KiB
C++
103 lines
2.8 KiB
C++
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "test_agg_merge.h"
|
|
|
|
#include <cassert>
|
|
#include <deque>
|
|
#include <vector>
|
|
|
|
#include "util/coding.h"
|
|
#include "utilities/agg_merge/agg_merge_impl.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
std::string EncodeHelper::EncodeFuncAndInt(const Slice& function_name,
|
|
int64_t value) {
|
|
std::string encoded_value;
|
|
PutVarsignedint64(&encoded_value, value);
|
|
std::string ret;
|
|
Status s = EncodeAggFuncAndPayload(function_name, encoded_value, ret);
|
|
assert(s.ok());
|
|
return ret;
|
|
}
|
|
|
|
std::string EncodeHelper::EncodeInt(int64_t value) {
|
|
std::string encoded_value;
|
|
PutVarsignedint64(&encoded_value, value);
|
|
return encoded_value;
|
|
}
|
|
|
|
std::string EncodeHelper::EncodeFuncAndList(const Slice& function_name,
|
|
const std::vector<Slice>& list) {
|
|
std::string ret;
|
|
Status s = EncodeAggFuncAndPayload(function_name, EncodeList(list), ret);
|
|
assert(s.ok());
|
|
return ret;
|
|
}
|
|
|
|
std::string EncodeHelper::EncodeList(const std::vector<Slice>& list) {
|
|
std::string result;
|
|
for (const Slice& entity : list) {
|
|
PutLengthPrefixedSlice(&result, entity);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool SumAggregator::Aggregate(const std::vector<Slice>& item_list,
|
|
std::string& result) const {
|
|
int64_t sum = 0;
|
|
for (const Slice& item : item_list) {
|
|
int64_t ivalue;
|
|
Slice v = item;
|
|
if (!GetVarsignedint64(&v, &ivalue) || !v.empty()) {
|
|
return false;
|
|
}
|
|
sum += ivalue;
|
|
}
|
|
result = EncodeHelper::EncodeInt(sum);
|
|
return true;
|
|
}
|
|
|
|
bool MultipleAggregator::Aggregate(const std::vector<Slice>& item_list,
|
|
std::string& result) const {
|
|
int64_t mresult = 1;
|
|
for (const Slice& item : item_list) {
|
|
int64_t ivalue;
|
|
Slice v = item;
|
|
if (!GetVarsignedint64(&v, &ivalue) || !v.empty()) {
|
|
return false;
|
|
}
|
|
mresult *= ivalue;
|
|
}
|
|
result = EncodeHelper::EncodeInt(mresult);
|
|
return true;
|
|
}
|
|
|
|
bool Last3Aggregator::Aggregate(const std::vector<Slice>& item_list,
|
|
std::string& result) const {
|
|
std::vector<Slice> last3;
|
|
last3.reserve(3);
|
|
for (auto it = item_list.rbegin(); it != item_list.rend(); ++it) {
|
|
Slice input = *it;
|
|
Slice entity;
|
|
bool ret;
|
|
while ((ret = GetLengthPrefixedSlice(&input, &entity)) == true) {
|
|
last3.push_back(entity);
|
|
if (last3.size() >= 3) {
|
|
break;
|
|
}
|
|
}
|
|
if (last3.size() >= 3) {
|
|
break;
|
|
}
|
|
if (!ret) {
|
|
continue;
|
|
}
|
|
}
|
|
result = EncodeHelper::EncodeList(last3);
|
|
return true;
|
|
}
|
|
} // namespace ROCKSDB_NAMESPACE
|