Optimizations to filter match drawing.

Store the filter match index on the SourcePathComponentNode so we can
retrieve it directly when drawing instead of having to recompute the
position of the match every time.
This commit is contained in:
Rene Gollent
2013-06-05 22:02:44 -04:00
parent 7d4a7ce33e
commit faa0580b62
@@ -49,7 +49,8 @@ public:
fParent(parent), fParent(parent),
fComponentName(componentName), fComponentName(componentName),
fSourceFile(sourceFile), fSourceFile(sourceFile),
fFunction(function) fFunction(function),
fFilterMatchIndex(-1)
{ {
if (fSourceFile != NULL) if (fSourceFile != NULL)
fSourceFile->AcquireReference(); fSourceFile->AcquireReference();
@@ -136,6 +137,16 @@ public:
return true; return true;
} }
int32 FilterMatchIndex() const
{
return fFilterMatchIndex;
}
void SetFilterMatchIndex(int32 index)
{
fFilterMatchIndex = index;
}
private: private:
friend class ImageFunctionsView::FunctionsTableModel; friend class ImageFunctionsView::FunctionsTableModel;
@@ -160,6 +171,7 @@ private:
LocatableFile* fSourceFile; LocatableFile* fSourceFile;
FunctionInstance* fFunction; FunctionInstance* fFunction;
ChildPathComponentList fChildPathComponents; ChildPathComponentList fChildPathComponents;
int32 fFilterMatchIndex;
}; };
@@ -198,15 +210,17 @@ public:
if (fField.HasClippedString()) if (fField.HasClippedString())
return; return;
const char* fieldString = fField.String(); const SourcePathComponentNode* node
const char* filterMatch = strstr(fieldString, fFilter.String()); = (const SourcePathComponentNode*)value.ToPointer();
if (filterMatch == NULL)
int32 matchIndex = node->FilterMatchIndex();
if (matchIndex < 0)
return; return;
targetView->PushState(); targetView->PushState();
BRect fillRect(rect); BRect fillRect(rect);
fillRect.left += kTextMargin + targetView->StringWidth( fillRect.left += kTextMargin + targetView->StringWidth(
fieldString, filterMatch - fieldString); fField.String(), matchIndex);
fillRect.right = fillRect.left + fFilterWidth; fillRect.right = fillRect.left + fFilterWidth;
targetView->SetLowColor(255, 255, 0, 255); targetView->SetLowColor(255, 255, 0, 255);
targetView->SetDrawingMode(B_OP_MIN); targetView->SetDrawingMode(B_OP_MIN);
@@ -215,6 +229,16 @@ public:
} }
} }
virtual BField* PrepareField(const BVariant& value) const
{
const SourcePathComponentNode* node
= (const SourcePathComponentNode*)value.ToPointer();
BVariant tempValue(node->ComponentName(), B_VARIANT_DONT_COPY_DATA);
return StringTableColumn::PrepareField(tempValue);
}
private: private:
BString fFilter; BString fFilter;
@@ -289,12 +313,18 @@ public:
if (sourceFile != NULL) if (sourceFile != NULL)
sourceFile->GetPath(sourcePath); sourceFile->GetPath(sourcePath);
if (applyFilter && !_FilterFunction(instance, sourcePath)) int32 pathMatchIndex = -1;
int32 functionMatchIndex = -1;
if (applyFilter && !_FilterFunction(instance, sourcePath,
pathMatchIndex, functionMatchIndex)) {
continue; continue;
}
if (sourceFile == NULL) { if (sourceFile == NULL) {
if (!_AddFunctionNode(sourcelessNode, instance, NULL)) if (!_AddFunctionNode(sourcelessNode, instance, NULL,
functionMatchIndex)) {
return; return;
}
continue; continue;
} }
@@ -311,9 +341,11 @@ public:
} }
} }
if (!_AddFunctionByPath(pathComponents, instance, currentFile)) if (!_AddFunctionByPath(pathComponents, instance, currentFile,
pathMatchIndex, functionMatchIndex)) {
return; return;
} }
}
if (sourcelessNode->CountChildren() != 0) { if (sourcelessNode->CountChildren() != 0) {
if (fChildPathComponents.BinaryInsert(sourcelessNode, if (fChildPathComponents.BinaryInsert(sourcelessNode,
@@ -362,7 +394,7 @@ public:
SourcePathComponentNode* node = (SourcePathComponentNode*)object; SourcePathComponentNode* node = (SourcePathComponentNode*)object;
value.SetTo(node->ComponentName(), B_VARIANT_DONT_COPY_DATA); value.SetTo(node);
return true; return true;
} }
@@ -472,7 +504,8 @@ private:
} }
bool _AddFunctionByPath(const BStringList& pathComponents, bool _AddFunctionByPath(const BStringList& pathComponents,
FunctionInstance* function, LocatableFile* file) FunctionInstance* function, LocatableFile* file, int32 pathMatchIndex,
int32 functionMatchIndex)
{ {
SourcePathComponentNode* parentNode = NULL; SourcePathComponentNode* parentNode = NULL;
SourcePathComponentNode* currentNode = NULL; SourcePathComponentNode* currentNode = NULL;
@@ -490,6 +523,10 @@ private:
parentNode, pathComponent, NULL, NULL); parentNode, pathComponent, NULL, NULL);
if (currentNode == NULL) if (currentNode == NULL)
return false; return false;
if (pathComponents.CountStrings() == 1)
currentNode->SetFilterMatchIndex(pathMatchIndex);
BReference<SourcePathComponentNode> nodeReference(currentNode, BReference<SourcePathComponentNode> nodeReference(currentNode,
true); true);
if (parentNode != NULL) { if (parentNode != NULL) {
@@ -507,11 +544,12 @@ private:
parentNode = currentNode; parentNode = currentNode;
} }
return _AddFunctionNode(currentNode, function, file); return _AddFunctionNode(currentNode, function, file,
functionMatchIndex);
} }
bool _AddFunctionNode(SourcePathComponentNode* parent, bool _AddFunctionNode(SourcePathComponentNode* parent,
FunctionInstance* function, LocatableFile* file) FunctionInstance* function, LocatableFile* file, int32 matchIndex)
{ {
SourcePathComponentNode* functionNode = new(std::nothrow) SourcePathComponentNode* functionNode = new(std::nothrow)
SourcePathComponentNode(parent, function->PrettyName(), file, SourcePathComponentNode(parent, function->PrettyName(), file,
@@ -520,6 +558,8 @@ private:
if (functionNode == NULL) if (functionNode == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
functionNode->SetFilterMatchIndex(matchIndex);
BReference<SourcePathComponentNode> nodeReference(functionNode, true); BReference<SourcePathComponentNode> nodeReference(functionNode, true);
if (!parent->AddChild(functionNode)) if (!parent->AddChild(functionNode))
return false; return false;
@@ -527,12 +567,13 @@ private:
return true; return true;
} }
bool _FilterFunction(FunctionInstance* instance, const BString& sourcePath) bool _FilterFunction(FunctionInstance* instance, const BString& sourcePath,
int32& pathMatchIndex, int32& functionMatchIndex)
{ {
if (instance->PrettyName().IFindFirst(fCurrentFilter) >= 0) functionMatchIndex = instance->PrettyName().IFindFirst(fCurrentFilter);
return true; pathMatchIndex = sourcePath.IFindFirst(fCurrentFilter);
return sourcePath.IFindFirst(fCurrentFilter) >= 0; return functionMatchIndex >= 0 || pathMatchIndex >= 0;
} }