Issue description
Very low prio thing. Filing this bug just to not lose track.
This came up while reviewing
https://codereview.chromium.org/2772283003/
Essentially my thought is to:
- make the whitelist flat array a radix tree (See example below)
- when matching, use base::CStringTokenizer(dump_name, "/")
- do the matching by walking the radix tree.
This will:
- reduce the number of string comparison we do for each |dump_name|.
- allow to express things like /foo/{1,2,3}/bar, without having to explicitly list
the combinatorial explosion: /foo/1/bar, /foo/2/bar, /foo/3/bar
Draft:
-----
$ g++ -o test test.cc --std=c++11 && ./test
<blink_gc>
<allocated_objects>
<net>
<url_request_context>
<app_request, extensions, isolated_media>
<0x?>
<http_cache>
<http_network_session>
<sdch_manager>
$ cat test.cc
#include <initializer_list>
#include <vector>
#include <string>
#include <string.h>
struct WhitelistNode {
using AnyKey = std::initializer_list<const char*>;
explicit WhitelistNode(AnyKey keys) : WhitelistNode(keys, {}) {}
explicit WhitelistNode(const char *key) : WhitelistNode(key, {}) {}
WhitelistNode(const char *key, std::initializer_list<WhitelistNode> children)
: WhitelistNode({key}, children) {}
WhitelistNode(AnyKey keys, std::initializer_list<WhitelistNode> children)
: keys{keys}, children(children) {}
bool match(const char *piece) const {
return false;// TODO implement this;
}
std::vector<const char*> keys;
std::vector<WhitelistNode> children;
};
using Whitelist = std::vector<WhitelistNode>;
const Whitelist& GetWhitelist() {
using WL = WhitelistNode;
static Whitelist whitelist{
WL("blink_gc", {
WL("allocated_objects")
}),
WL("net", {
WL("url_request_context", {
WL(WL::AnyKey{"app_request", "extensions", "isolated_media"}, {
WL("0x?", {
WL("http_cache"),
WL("http_network_session"),
WL("sdch_manager")
})
})
})
})
};
return whitelist;
};
void Dump(const Whitelist& list, std::string pfx) {
for (const auto& entry : list) {
printf("%s<", pfx.c_str());
for (const char* key : entry.keys)
printf("%s%s", key, key != entry.keys.back() ? ", " : "");
printf(">\n");
Dump(entry.children, pfx + " ");
}
};
int main() {
Dump(GetWhitelist(), "");
}
return false;// TODO implement this;
}
std::vector<const char*> keys;
Whitelist children;
};
const Whitelist& GetWhitelist() {
using WL = WhitelistNode;
static Whitelist whitelist{
WL("blink_gc", {
WL("allocated_objects")
}),
WL("net", {
WL("url_request_context", {
WL(WL::AnyKey{"app_request", "extensions", "isolated_media"}, {
WL("0x?", {
WL("http_cache"),
WL("http_network_session"),
WL("sdch_manager")
})
})
})
})
};
return whitelist;
};
void Dump(const Whitelist& list, std::string pfx) {
for (const auto& entry : list) {
printf("%s<", pfx.c_str());
for (const char* key : entry.keys)
printf("%s%s", key, key != entry.keys.back() ? ", " : "");
printf(">\n");
Dump(entry.children, pfx + " ");
}
};
int main() {
Dump(GetWhitelist(), "");
}
Very low prio thing. Filing this bug just to not lose track.
This came up while reviewing
https://codereview.chromium.org/2772283003/
Essentially my thought is to:
- make the whitelist flat array a radix tree (See example below)
- when matching, use base::CStringTokenizer(dump_name, "/")
- do the matching by walking the radix tree.
This will:
- reduce the number of string comparison we do for each |dump_name|.
- allow to express things like /foo/{1,2,3}/bar, without having to explicitly list
the combinatorial explosion: /foo/1/bar, /foo/2/bar, /foo/3/bar
Draft:
-----
$ g++ -o test test.cc --std=c++11 && ./test
<blink_gc>
<allocated_objects>
<net>
<url_request_context>
<app_request, extensions, isolated_media>
<0x?>
<http_cache>
<http_network_session>
<sdch_manager>
$ cat test.cc
#include <initializer_list>
#include <vector>
#include <string>
#include <string.h>
struct WhitelistNode {
using AnyKey = std::initializer_list<const char*>;
explicit WhitelistNode(AnyKey keys) : WhitelistNode(keys, {}) {}
explicit WhitelistNode(const char *key) : WhitelistNode(key, {}) {}
WhitelistNode(const char *key, std::initializer_list<WhitelistNode> children)
: WhitelistNode({key}, children) {}
WhitelistNode(AnyKey keys, std::initializer_list<WhitelistNode> children)
: keys{keys}, children(children) {}
bool match(const char *piece) const {
return false;// TODO implement this;
}
std::vector<const char*> keys;
std::vector<WhitelistNode> children;
};
using Whitelist = std::vector<WhitelistNode>;
const Whitelist& GetWhitelist() {
using WL = WhitelistNode;
static Whitelist whitelist{
WL("blink_gc", {
WL("allocated_objects")
}),
WL("net", {
WL("url_request_context", {
WL(WL::AnyKey{"app_request", "extensions", "isolated_media"}, {
WL("0x?", {
WL("http_cache"),
WL("http_network_session"),
WL("sdch_manager")
})
})
})
})
};
return whitelist;
};
void Dump(const Whitelist& list, std::string pfx) {
for (const auto& entry : list) {
printf("%s<", pfx.c_str());
for (const char* key : entry.keys)
printf("%s%s", key, key != entry.keys.back() ? ", " : "");
printf(">\n");
Dump(entry.children, pfx + " ");
}
};
int main() {
Dump(GetWhitelist(), "");
}
|
Comment 1 by primiano@chromium.org
, Mar 28 2017