mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 975823, part 12 - Inline BFSState into BFSTableData. r=mcmanus
This commit is contained in:
parent
17e5685a84
commit
2016935adb
@ -37,18 +37,6 @@
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Breadth-First-Search (BFS) algorithm state classes and types.
|
||||
|
||||
// used to establish discovered vertecies.
|
||||
enum BFScolors {white, gray, black};
|
||||
|
||||
struct BFSState {
|
||||
BFScolors color;
|
||||
int32_t distance;
|
||||
nsCStringKey *predecessor;
|
||||
~BFSState() {
|
||||
delete predecessor;
|
||||
}
|
||||
};
|
||||
|
||||
// Adjacency list data class.
|
||||
typedef nsCOMArray<nsIAtom> SCTableData;
|
||||
|
||||
@ -59,14 +47,24 @@ static bool DeleteAdjacencyEntry(nsHashKey *aKey, void *aData, void* closure) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Used to establish discovered verticies.
|
||||
enum BFScolors {white, gray, black};
|
||||
|
||||
// BFS hashtable data class.
|
||||
struct BFSTableData {
|
||||
nsCStringKey *key;
|
||||
BFSState *state;
|
||||
BFScolors color;
|
||||
int32_t distance;
|
||||
nsCStringKey *predecessor;
|
||||
|
||||
BFSTableData(nsCStringKey* aKey) : key(aKey), state(nullptr)
|
||||
explicit BFSTableData(nsCStringKey* aKey)
|
||||
: key(aKey), color(white), distance(-1), predecessor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~BFSTableData() {
|
||||
delete predecessor;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -215,24 +213,13 @@ static bool InitBFSTable(nsHashKey *aKey, void *aData, void* closure) {
|
||||
nsHashtable *BFSTable = (nsHashtable*)closure;
|
||||
if (!BFSTable) return false;
|
||||
|
||||
BFSState *state = new BFSState;
|
||||
|
||||
state->color = white;
|
||||
state->distance = -1;
|
||||
state->predecessor = nullptr;
|
||||
|
||||
BFSTableData *data = new BFSTableData(static_cast<nsCStringKey*>(aKey));
|
||||
data->state = state;
|
||||
|
||||
BFSTable->Put(aKey, data);
|
||||
BFSTable->Put(aKey, new BFSTableData(static_cast<nsCStringKey*>(aKey)));
|
||||
return true;
|
||||
}
|
||||
|
||||
// cleans up the BFS state table
|
||||
static bool DeleteBFSEntry(nsHashKey *aKey, void *aData, void *closure) {
|
||||
BFSTableData *data = (BFSTableData*)aData;
|
||||
BFSState *state = data->state;
|
||||
delete state;
|
||||
data->key = nullptr;
|
||||
delete data;
|
||||
return true;
|
||||
@ -282,10 +269,8 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
BFSState *state = data->state;
|
||||
|
||||
state->color = gray;
|
||||
state->distance = 0;
|
||||
data->color = gray;
|
||||
data->distance = 0;
|
||||
CStreamConvDeallocator *dtorFunc = new CStreamConvDeallocator();
|
||||
|
||||
nsDeque grayQ(dtorFunc);
|
||||
@ -299,11 +284,7 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
|
||||
// Get the state of the current head to calculate the distance of each
|
||||
// reachable vertex in the loop.
|
||||
BFSTableData *data2b = (BFSTableData*)lBFSTable.Get(currentHead);
|
||||
if (!data2b) return NS_ERROR_FAILURE;
|
||||
|
||||
BFSState *headVertexState = data2b->state;
|
||||
NS_ASSERTION(headVertexState, "problem with the BFS strmconv algorithm");
|
||||
BFSTableData *headVertexState = (BFSTableData*)lBFSTable.Get(currentHead);
|
||||
if (!headVertexState) return NS_ERROR_FAILURE;
|
||||
|
||||
int32_t edgeCount = data2->Count();
|
||||
@ -315,14 +296,11 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
nsCStringKey *curVertex = new nsCStringKey(ToNewCString(curVertexStr),
|
||||
curVertexStr.Length(), nsCStringKey::OWN);
|
||||
|
||||
BFSTableData *data3 = (BFSTableData*)lBFSTable.Get(curVertex);
|
||||
if (!data3) {
|
||||
BFSTableData *curVertexState = (BFSTableData*)lBFSTable.Get(curVertex);
|
||||
if (!curVertexState) {
|
||||
delete curVertex;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
BFSState *curVertexState = data3->state;
|
||||
NS_ASSERTION(curVertexState, "something went wrong with the BFS strmconv algorithm");
|
||||
if (!curVertexState) return NS_ERROR_FAILURE;
|
||||
|
||||
if (white == curVertexState->color) {
|
||||
curVertexState->color = gray;
|
||||
@ -344,8 +322,8 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
delete cur;
|
||||
cur = nullptr;
|
||||
}
|
||||
// The shortest path (if any) has been generated and is represetned by the chain of
|
||||
// BFSState->predecessor keys. Start at the bottom and work our way up.
|
||||
// The shortest path (if any) has been generated and is represented by the chain of
|
||||
// BFSTableData->predecessor keys. Start at the bottom and work our way up.
|
||||
|
||||
// first parse out the FROM and TO MIME-types being registered.
|
||||
|
||||
@ -367,8 +345,6 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
}
|
||||
|
||||
while (data) {
|
||||
BFSState *curState = data->state;
|
||||
|
||||
nsCStringKey *key = data->key;
|
||||
|
||||
if (fromStr.Equals(key->GetString())) {
|
||||
@ -379,8 +355,8 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCStr
|
||||
|
||||
// reconstruct the CONTRACTID.
|
||||
// Get the predecessor.
|
||||
if (!curState->predecessor) break; // no predecessor
|
||||
BFSTableData *predecessorData = (BFSTableData*)lBFSTable.Get(curState->predecessor);
|
||||
if (!data->predecessor) break; // no predecessor
|
||||
BFSTableData *predecessorData = (BFSTableData*)lBFSTable.Get(data->predecessor);
|
||||
|
||||
if (!predecessorData) break; // no predecessor, chain doesn't exist.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user