BFS: Use the shared QueryParser.
Ideally should have no functional changes from the old one. Change-Id: Id557d8fb069603221887447597ef0ffce5de07a6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7705 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
7da55c7296
commit
0a44afc6bf
@@ -337,7 +337,7 @@ private:
|
||||
|
||||
class NodeGetter : public CachedBlock {
|
||||
public:
|
||||
NodeGetter(Volume* volume)
|
||||
NodeGetter(Volume* volume = NULL)
|
||||
:
|
||||
CachedBlock(volume)
|
||||
{
|
||||
@@ -349,6 +349,8 @@ public:
|
||||
|
||||
status_t SetTo(const Inode* inode)
|
||||
{
|
||||
Unset();
|
||||
fVolume = inode->GetVolume();
|
||||
return CachedBlock::SetTo(fVolume->VnodeToBlock(inode->ID()));
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2024, Haiku, Inc. All rights reserved.
|
||||
* This file may be used under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef QUERY_H
|
||||
@@ -10,70 +11,47 @@
|
||||
#include "Index.h"
|
||||
|
||||
|
||||
class Volume;
|
||||
class Term;
|
||||
class Equation;
|
||||
class TreeIterator;
|
||||
class Query;
|
||||
|
||||
|
||||
class Expression {
|
||||
public:
|
||||
Expression(char* expr);
|
||||
~Expression();
|
||||
|
||||
status_t InitCheck();
|
||||
const char* Position() const { return fPosition; }
|
||||
Term* Root() const { return fTerm; }
|
||||
|
||||
protected:
|
||||
Term* ParseOr(char** expr);
|
||||
Term* ParseAnd(char** expr);
|
||||
Term* ParseEquation(char** expr);
|
||||
|
||||
bool IsOperator(char** expr, char op);
|
||||
|
||||
private:
|
||||
Expression(const Expression& other);
|
||||
Expression& operator=(const Expression& other);
|
||||
// no implementation
|
||||
|
||||
char* fPosition;
|
||||
Term* fTerm;
|
||||
namespace QueryParser {
|
||||
template<typename QueryPolicy> class Query;
|
||||
};
|
||||
|
||||
class Query : public SinglyLinkedListLinkImpl<Query> {
|
||||
class Volume;
|
||||
|
||||
|
||||
class Query : public DoublyLinkedListLinkImpl<Query> {
|
||||
public:
|
||||
Query(Volume* volume, Expression* expression,
|
||||
uint32 flags);
|
||||
~Query();
|
||||
|
||||
status_t Rewind();
|
||||
status_t GetNextEntry(struct dirent* , size_t size);
|
||||
static status_t Create(Volume* volume, const char* queryString,
|
||||
uint32 flags, port_id port, uint32 token,
|
||||
Query*& _query);
|
||||
|
||||
void SetLiveMode(port_id port, int32 token);
|
||||
void LiveUpdate(Inode* inode, const char* attribute,
|
||||
int32 type, const uint8* oldKey,
|
||||
size_t oldLength, const uint8* newKey,
|
||||
size_t newLength);
|
||||
void LiveUpdateRenameMove(Inode* inode,
|
||||
status_t Rewind();
|
||||
status_t GetNextEntry(struct dirent* entry, size_t size);
|
||||
|
||||
void LiveUpdate(Inode* inode,
|
||||
const char* attribute, int32 type,
|
||||
const void* oldKey, size_t oldLength,
|
||||
const void* newKey, size_t newLength);
|
||||
void LiveUpdateRenameMove(Inode* node,
|
||||
ino_t oldDirectoryID, const char* oldName,
|
||||
size_t oldLength, ino_t newDirectoryID,
|
||||
const char* newName, size_t newLength);
|
||||
private:
|
||||
struct QueryPolicy;
|
||||
friend struct QueryPolicy;
|
||||
typedef QueryParser::Query<QueryPolicy> QueryImpl;
|
||||
|
||||
Expression* GetExpression() const { return fExpression; }
|
||||
private:
|
||||
Query(Volume* volume);
|
||||
|
||||
status_t _Init(const char* queryString, uint32 flags,
|
||||
port_id port, uint32 token);
|
||||
|
||||
private:
|
||||
Volume* fVolume;
|
||||
Expression* fExpression;
|
||||
Equation* fCurrent;
|
||||
TreeIterator* fIterator;
|
||||
Index fIndex;
|
||||
Stack<Equation*> fStack;
|
||||
|
||||
uint32 fFlags;
|
||||
port_id fPort;
|
||||
int32 fToken;
|
||||
QueryImpl* fImpl;
|
||||
};
|
||||
|
||||
|
||||
#endif // QUERY_H
|
||||
|
||||
@@ -413,7 +413,7 @@ Volume::UpdateLiveQueries(Inode* inode, const char* attribute, int32 type,
|
||||
{
|
||||
MutexLocker _(fQueryLock);
|
||||
|
||||
SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
|
||||
DoublyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
|
||||
while (iterator.HasNext()) {
|
||||
Query* query = iterator.Next();
|
||||
query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey,
|
||||
@@ -431,7 +431,7 @@ Volume::UpdateLiveQueriesRenameMove(Inode* inode, ino_t oldDirectoryID,
|
||||
size_t oldLength = strlen(oldName);
|
||||
size_t newLength = strlen(newName);
|
||||
|
||||
SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
|
||||
DoublyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
|
||||
while (iterator.HasNext()) {
|
||||
Query* query = iterator.Next();
|
||||
query->LiveUpdateRenameMove(inode, oldDirectoryID, oldName, oldLength,
|
||||
|
||||
@@ -173,7 +173,7 @@ protected:
|
||||
vint32 fDirtyCachedBlocks;
|
||||
|
||||
mutex fQueryLock;
|
||||
SinglyLinkedList<Query> fQueries;
|
||||
DoublyLinkedList<Query> fQueries;
|
||||
|
||||
uint32 fFlags;
|
||||
|
||||
|
||||
@@ -2268,26 +2268,10 @@ bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags,
|
||||
|
||||
Volume* volume = (Volume*)_volume->private_volume;
|
||||
|
||||
Expression* expression = new(std::nothrow) Expression((char*)queryString);
|
||||
if (expression == NULL)
|
||||
RETURN_ERROR(B_NO_MEMORY);
|
||||
|
||||
if (expression->InitCheck() < B_OK) {
|
||||
INFORM(("Could not parse query \"%s\", stopped at: \"%s\"\n",
|
||||
queryString, expression->Position()));
|
||||
|
||||
delete expression;
|
||||
RETURN_ERROR(B_BAD_VALUE);
|
||||
}
|
||||
|
||||
Query* query = new(std::nothrow) Query(volume, expression, flags);
|
||||
if (query == NULL) {
|
||||
delete expression;
|
||||
RETURN_ERROR(B_NO_MEMORY);
|
||||
}
|
||||
|
||||
if (flags & B_LIVE_QUERY)
|
||||
query->SetLiveMode(port, token);
|
||||
Query* query;
|
||||
status_t error = Query::Create(volume, queryString, flags, port, token, query);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
*_cookie = (void*)query;
|
||||
|
||||
@@ -2309,9 +2293,7 @@ bfs_free_query_cookie(fs_volume* _volume, void* cookie)
|
||||
FUNCTION();
|
||||
|
||||
Query* query = (Query*)cookie;
|
||||
Expression* expression = query->GetExpression();
|
||||
delete query;
|
||||
delete expression;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user