Rework source path parsing.
- As we parse the image's function list, we now track the last source file we encountered. If it's the first time we encounter the current file, we parse its source path components up front and then simply walk the parsed list in order to add the function to its appropriate place in the model, rather than the previous recursive approach. This allows us to reuse the parsed component list for subsequent functions in the same source file rather than having to reparse the path on every iteration. - Refactor GetFunctionPath() to make use of the new _GetSourcePathComponents() parsing function. Should further improve the time needed to change the active image.
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include <StringList.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include "table/TableColumns.h"
|
#include "table/TableColumns.h"
|
||||||
@@ -194,6 +196,8 @@ public:
|
|||||||
BReference<SourcePathComponentNode> sourceNodeRef(
|
BReference<SourcePathComponentNode> sourceNodeRef(
|
||||||
sourcelessNode, true);
|
sourcelessNode, true);
|
||||||
|
|
||||||
|
LocatableFile* currentFile = NULL;
|
||||||
|
BStringList pathComponents;
|
||||||
int32 functionCount = fImageDebugInfo->CountFunctions();
|
int32 functionCount = fImageDebugInfo->CountFunctions();
|
||||||
for (int32 i = 0; i < functionCount; i++) {
|
for (int32 i = 0; i < functionCount; i++) {
|
||||||
FunctionInstance* instance = fImageDebugInfo->FunctionAt(i);
|
FunctionInstance* instance = fImageDebugInfo->FunctionAt(i);
|
||||||
@@ -208,7 +212,22 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_BuildFunctionSourcePath(instance, sourcelessNode))
|
LocatableFile* sourceFile = instance->SourceFile();
|
||||||
|
if (sourceFile == NULL) {
|
||||||
|
if (!_AddFunctionNode(sourcelessNode, instance, NULL))
|
||||||
|
return;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceFile != currentFile) {
|
||||||
|
currentFile = sourceFile;
|
||||||
|
if (!_GetSourcePathComponents(currentFile,
|
||||||
|
pathComponents)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_AddFunctionByPath(pathComponents, instance, currentFile))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,30 +295,20 @@ public:
|
|||||||
node = fSourcelessNode;
|
node = fSourcelessNode;
|
||||||
_path.AddComponent(fChildPathComponents.IndexOf(node));
|
_path.AddComponent(fChildPathComponents.IndexOf(node));
|
||||||
} else {
|
} else {
|
||||||
BString sourcePath;
|
BStringList pathComponents;
|
||||||
sourceFile->GetPath(sourcePath);
|
if (!_GetSourcePathComponents(sourceFile, pathComponents))
|
||||||
|
|
||||||
if (sourcePath.IsEmpty())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BString searchPath;
|
for (int32 i = 0; i < pathComponents.CountStrings(); i++) {
|
||||||
while (!sourcePath.IsEmpty()) {
|
BString component = pathComponents.StringAt(i);
|
||||||
if (sourcePath[0] == '/')
|
|
||||||
sourcePath.Remove(0, 1);
|
|
||||||
int32 separatorIndex = sourcePath.FindFirst('/');
|
|
||||||
if (separatorIndex == -1) {
|
|
||||||
searchPath = sourcePath;
|
|
||||||
sourcePath.Truncate(0);
|
|
||||||
} else
|
|
||||||
sourcePath.MoveInto(searchPath, 0, separatorIndex);
|
|
||||||
|
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
childIndex = fChildPathComponents.BinarySearchIndexByKey(
|
childIndex = fChildPathComponents.BinarySearchIndexByKey(
|
||||||
searchPath,
|
component,
|
||||||
&SourcePathComponentNode::CompareByComponentName);
|
&SourcePathComponentNode::CompareByComponentName);
|
||||||
node = fChildPathComponents.ItemAt(childIndex);
|
node = fChildPathComponents.ItemAt(childIndex);
|
||||||
} else {
|
} else {
|
||||||
childIndex = node->FindChildIndexByName(searchPath);
|
childIndex = node->FindChildIndexByName(component);
|
||||||
node = node->ChildAt(childIndex);
|
node = node->ChildAt(childIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,65 +352,73 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _BuildFunctionSourcePath(FunctionInstance* function,
|
bool _GetSourcePathComponents(LocatableFile* currentFile,
|
||||||
SourcePathComponentNode* sourcelessNode)
|
BStringList& pathComponents)
|
||||||
{
|
{
|
||||||
LocatableFile* sourceFile = function->SourceFile();
|
|
||||||
if (sourceFile == NULL)
|
|
||||||
return _AddFunctionNode(sourcelessNode, function, NULL);
|
|
||||||
|
|
||||||
BString sourcePath;
|
BString sourcePath;
|
||||||
sourceFile->GetPath(sourcePath);
|
currentFile->GetPath(sourcePath);
|
||||||
if (sourcePath.IsEmpty())
|
if (sourcePath.IsEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _AddNextPathComponent(NULL, sourcePath, function, sourceFile);
|
pathComponents.MakeEmpty();
|
||||||
}
|
|
||||||
|
|
||||||
bool _AddNextPathComponent(SourcePathComponentNode* parent,
|
int32 startIndex = 0;
|
||||||
BString& childPath, FunctionInstance* function, LocatableFile* file)
|
if (sourcePath[0] == '/')
|
||||||
{
|
startIndex = 1;
|
||||||
if (childPath[0] == '/')
|
|
||||||
childPath.Remove(0, 1);
|
|
||||||
|
|
||||||
BString pathComponent;
|
while (startIndex < sourcePath.Length()) {
|
||||||
int32 pathSeparatorIndex = childPath.FindFirst('/');
|
int32 searchIndex = sourcePath.FindFirst('/', startIndex);
|
||||||
if (pathSeparatorIndex == -1)
|
BString data;
|
||||||
pathComponent = childPath;
|
if (searchIndex < 0)
|
||||||
else
|
searchIndex = sourcePath.Length();
|
||||||
childPath.MoveInto(pathComponent, 0, pathSeparatorIndex);
|
|
||||||
|
|
||||||
SourcePathComponentNode* currentNode = NULL;
|
sourcePath.CopyInto(data, startIndex, searchIndex - startIndex);
|
||||||
if (parent == NULL) {
|
if (!pathComponents.Add(data))
|
||||||
currentNode = fChildPathComponents.BinarySearchByKey(pathComponent,
|
|
||||||
SourcePathComponentNode::CompareByComponentName);
|
|
||||||
} else
|
|
||||||
currentNode = parent->FindChildByName(pathComponent);
|
|
||||||
|
|
||||||
if (currentNode == NULL) {
|
|
||||||
currentNode = new(std::nothrow) SourcePathComponentNode(parent,
|
|
||||||
pathComponent, NULL, NULL);
|
|
||||||
if (currentNode == NULL)
|
|
||||||
return false;
|
return false;
|
||||||
BReference<SourcePathComponentNode> nodeReference(currentNode,
|
|
||||||
true);
|
|
||||||
if (parent != NULL) {
|
|
||||||
if (!parent->AddChild(currentNode))
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!fChildPathComponents.BinaryInsert(currentNode,
|
|
||||||
&SourcePathComponentNode::CompareComponents)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeReference.Detach();
|
startIndex = searchIndex + 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pathSeparatorIndex == -1)
|
return true;
|
||||||
return _AddFunctionNode(currentNode, function, file);
|
}
|
||||||
|
|
||||||
return _AddNextPathComponent(currentNode, childPath, function, file);
|
bool _AddFunctionByPath(const BStringList& pathComponents,
|
||||||
|
FunctionInstance* function, LocatableFile* file)
|
||||||
|
{
|
||||||
|
SourcePathComponentNode* parentNode = NULL;
|
||||||
|
SourcePathComponentNode* currentNode = NULL;
|
||||||
|
for (int32 i = 0; i < pathComponents.CountStrings(); i++) {
|
||||||
|
const BString pathComponent = pathComponents.StringAt(i);
|
||||||
|
if (parentNode == NULL) {
|
||||||
|
currentNode = fChildPathComponents.BinarySearchByKey(
|
||||||
|
pathComponent,
|
||||||
|
SourcePathComponentNode::CompareByComponentName);
|
||||||
|
} else
|
||||||
|
currentNode = parentNode->FindChildByName(pathComponent);
|
||||||
|
|
||||||
|
if (currentNode == NULL) {
|
||||||
|
currentNode = new(std::nothrow) SourcePathComponentNode(
|
||||||
|
parentNode, pathComponent, NULL, NULL);
|
||||||
|
if (currentNode == NULL)
|
||||||
|
return false;
|
||||||
|
BReference<SourcePathComponentNode> nodeReference(currentNode,
|
||||||
|
true);
|
||||||
|
if (parentNode != NULL) {
|
||||||
|
if (!parentNode->AddChild(currentNode))
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!fChildPathComponents.BinaryInsert(currentNode,
|
||||||
|
&SourcePathComponentNode::CompareComponents)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeReference.Detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parentNode = currentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _AddFunctionNode(currentNode, function, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _AddFunctionNode(SourcePathComponentNode* parent,
|
bool _AddFunctionNode(SourcePathComponentNode* parent,
|
||||||
|
|||||||
Reference in New Issue
Block a user