Remove unused function CollectScalarVars()

This commit is contained in:
Noah Hilverling 2019-08-07 15:50:16 +02:00 committed by Michael Friedrich
parent 53d04cc4e8
commit d5d3f3e60c

View File

@ -130,87 +130,6 @@ String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object)
return HashValue(vars);
}
/**
* Collect the leaves of haystack in needles
*
* haystack = {
* "disks": {
* "disk": {},
* "disk /": {
* "disk_partitions": "/"
* }
* }
* }
*
* path = []
*
* needles = {
* "disks": [
* [
* ["disks", "disk /", "disk_partitions"],
* "/"
* ]
* ]
* }
*
* @param haystack A config object's custom vars as returned by {@link CustomVarObject#GetVars()}
* @param path Used for buffering only, shall be empty
* @param needles The result, a mapping from the top-level custom var key to a list of leaves with full path and value
*/
static void CollectScalarVars(Value haystack, std::vector<Value>& path, std::map<String, std::vector<std::pair<Array::Ptr, Value>>>& needles)
{
switch (haystack.GetType()) {
case ValueObject:
{
const Object::Ptr& obj = haystack.Get<Object::Ptr>();
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(obj);
if (dict) {
ObjectLock olock(dict);
for (auto& kv : dict) {
path.emplace_back(kv.first);
CollectScalarVars(kv.second, path, needles);
path.pop_back();
}
break;
}
Array::Ptr arr = dynamic_pointer_cast<Array>(obj);
if (arr) {
double index = 0.0;
ObjectLock xlock(arr);
for (auto& v : arr) {
path.emplace_back(index);
CollectScalarVars(v, path, needles);
path.pop_back();
index += 1.0;
}
break;
}
}
haystack = Empty;
case ValueString:
case ValueNumber:
case ValueBoolean:
case ValueEmpty:
needles[path[0].Get<String>()].emplace_back(Array::FromVector(path), haystack);
break;
default:
VERIFY(!"Invalid variant type.");
}
}
/**
* Prepare object's custom vars for being written to Redis
*
@ -234,7 +153,7 @@ static void CollectScalarVars(Value haystack, std::vector<Value>& path, std::map
* }
* }
* ])): {
* "env_checksum": SHA1(Environment),
* "envId": SHA1(Environment),
* "name_checksum": SHA1("disks"),
* "name": "disks",
* "value": {
@ -242,12 +161,6 @@ static void CollectScalarVars(Value haystack, std::vector<Value>& path, std::map
* "disk /": {
* "disk_partitions": "/"
* }
* },
* "flat": {
* SHA1(PackObject(["disks", "disk /", "disk_partitions"])): {
* "name": ["disks", "disk /", "disk_partitions"],
* "value": "/"
* }
* }
* }
* }
@ -263,13 +176,6 @@ Dictionary::Ptr RedisWriter::SerializeVars(const CustomVarObject::Ptr& object)
if (!vars)
return nullptr;
std::map<String, std::vector<std::pair<Array::Ptr, Value>>> scalarVars;
{
std::vector<Value> pathBuf;
CollectScalarVars(vars, pathBuf, scalarVars);
}
Dictionary::Ptr res = new Dictionary();
auto env (GetEnvironment());
auto envChecksum (SHA1(env));