mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
Define addString() and lookup() out-of-line to dissuade the C++ compiler from inlining it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45068 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -178,79 +178,85 @@ public:
|
|||||||
|
|
||||||
inline Node* getRoot() const { return Nodes[0]; }
|
inline Node* getRoot() const { return Nodes[0]; }
|
||||||
|
|
||||||
bool addString(const std::string& s, const Payload& data) {
|
bool addString(const std::string& s, const Payload& data);
|
||||||
Node* cNode = getRoot();
|
const Payload& lookup(const std::string& s) const;
|
||||||
Node* tNode = NULL;
|
|
||||||
std::string s1(s);
|
|
||||||
|
|
||||||
while (tNode == NULL) {
|
|
||||||
char Id = s1[0];
|
|
||||||
if (Node* nNode = cNode->getEdge(Id)) {
|
|
||||||
typename Node::QueryResult r = nNode->query(s1);
|
|
||||||
|
|
||||||
switch (r) {
|
|
||||||
case Node::Same:
|
|
||||||
case Node::StringIsPrefix:
|
|
||||||
// Currently we don't allow to have two strings in the trie one
|
|
||||||
// being a prefix of another. This should be fixed.
|
|
||||||
assert(0 && "FIXME!");
|
|
||||||
return false;
|
|
||||||
case Node::DontMatch:
|
|
||||||
assert(0 && "Impossible!");
|
|
||||||
return false;
|
|
||||||
case Node::LabelIsPrefix:
|
|
||||||
s1 = s1.substr(nNode->label().length());
|
|
||||||
cNode = nNode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
nNode = splitEdge(cNode, Id, r);
|
|
||||||
tNode = addNode(data, s1.substr(r));
|
|
||||||
nNode->addEdge(tNode);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tNode = addNode(data, s1);
|
|
||||||
cNode->addEdge(tNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Payload& lookup(const std::string& s) const {
|
|
||||||
Node* cNode = getRoot();
|
|
||||||
Node* tNode = NULL;
|
|
||||||
std::string s1(s);
|
|
||||||
|
|
||||||
while (tNode == NULL) {
|
|
||||||
char Id = s1[0];
|
|
||||||
if (Node* nNode = cNode->getEdge(Id)) {
|
|
||||||
typename Node::QueryResult r = nNode->query(s1);
|
|
||||||
|
|
||||||
switch (r) {
|
|
||||||
case Node::Same:
|
|
||||||
tNode = nNode;
|
|
||||||
break;
|
|
||||||
case Node::StringIsPrefix:
|
|
||||||
return Empty;
|
|
||||||
case Node::DontMatch:
|
|
||||||
assert(0 && "Impossible!");
|
|
||||||
return Empty;
|
|
||||||
case Node::LabelIsPrefix:
|
|
||||||
s1 = s1.substr(nNode->label().length());
|
|
||||||
cNode = nNode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return Empty;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
return Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tNode->data();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Define this out-of-line to dissuade the C++ compiler from inlining it.
|
||||||
|
template<class Payload>
|
||||||
|
bool Trie<Payload>::addString(const std::string& s, const Payload& data) {
|
||||||
|
Node* cNode = getRoot();
|
||||||
|
Node* tNode = NULL;
|
||||||
|
std::string s1(s);
|
||||||
|
|
||||||
|
while (tNode == NULL) {
|
||||||
|
char Id = s1[0];
|
||||||
|
if (Node* nNode = cNode->getEdge(Id)) {
|
||||||
|
typename Node::QueryResult r = nNode->query(s1);
|
||||||
|
|
||||||
|
switch (r) {
|
||||||
|
case Node::Same:
|
||||||
|
case Node::StringIsPrefix:
|
||||||
|
// Currently we don't allow to have two strings in the trie one
|
||||||
|
// being a prefix of another. This should be fixed.
|
||||||
|
assert(0 && "FIXME!");
|
||||||
|
return false;
|
||||||
|
case Node::DontMatch:
|
||||||
|
assert(0 && "Impossible!");
|
||||||
|
return false;
|
||||||
|
case Node::LabelIsPrefix:
|
||||||
|
s1 = s1.substr(nNode->label().length());
|
||||||
|
cNode = nNode;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nNode = splitEdge(cNode, Id, r);
|
||||||
|
tNode = addNode(data, s1.substr(r));
|
||||||
|
nNode->addEdge(tNode);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tNode = addNode(data, s1);
|
||||||
|
cNode->addEdge(tNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Payload>
|
||||||
|
const Payload& Trie<Payload>::lookup(const std::string& s) const {
|
||||||
|
Node* cNode = getRoot();
|
||||||
|
Node* tNode = NULL;
|
||||||
|
std::string s1(s);
|
||||||
|
|
||||||
|
while (tNode == NULL) {
|
||||||
|
char Id = s1[0];
|
||||||
|
if (Node* nNode = cNode->getEdge(Id)) {
|
||||||
|
typename Node::QueryResult r = nNode->query(s1);
|
||||||
|
|
||||||
|
switch (r) {
|
||||||
|
case Node::Same:
|
||||||
|
tNode = nNode;
|
||||||
|
break;
|
||||||
|
case Node::StringIsPrefix:
|
||||||
|
return Empty;
|
||||||
|
case Node::DontMatch:
|
||||||
|
assert(0 && "Impossible!");
|
||||||
|
return Empty;
|
||||||
|
case Node::LabelIsPrefix:
|
||||||
|
s1 = s1.substr(nNode->label().length());
|
||||||
|
cNode = nNode;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return Empty;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tNode->data();
|
||||||
|
}
|
||||||
|
|
||||||
template<class Payload>
|
template<class Payload>
|
||||||
struct GraphTraits<Trie<Payload> > {
|
struct GraphTraits<Trie<Payload> > {
|
||||||
typedef typename Trie<Payload>::Node NodeType;
|
typedef typename Trie<Payload>::Node NodeType;
|
||||||
|
Reference in New Issue
Block a user