Velocizzata la valutazione dei filtri sui cursori

git-svn-id: svn://10.65.10.50/trunk@5482 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1997-10-29 12:06:24 +00:00
parent 75d190f902
commit ea24bfa9be
2 changed files with 29 additions and 8 deletions

View File

@ -895,14 +895,15 @@ bool TRelation::exist(int logicnum) const
///////////////////////////////////////////////////////////
HIDDEN bool __evalcondition(const TRelation& r,TExpression* cond)
HIDDEN bool __evalcondition(const TRelation& r,TExpression* cond, const TArray & frefs)
{
TFieldref f;
// TFieldref f;
for (int i = cond->numvar() - 1; i >= 0; i--)
{
const TFixed_string s(cond->varname(i));
f = s;
cond->setvar(i, f.read(r));
// const TFixed_string s(cond->varname(i));
// f = s;
// f = cond->varname(i);
cond->setvar(i, (const char *) (TRecfield &)frefs[i]);
}
return (bool) *cond;
}
@ -1014,7 +1015,7 @@ int TCursor::filtercursor(int pagecnt, TRecnotype* page)
file().readat(rec,page[i]);
if (update_relation()) _if->update();
if ((_filterfunction ? _filterfunction(_if) : TRUE ) &&
(_fexpr ? __evalcondition(*_if, _fexpr) : TRUE))
(_fexpr ? __evalcondition(*_if, _fexpr, _frefs) : TRUE))
{
if (np < i) page[np] = page[i];
np++;
@ -1050,7 +1051,7 @@ bool TCursor::ok() const
_if->update();
if ((_filterfunction ? _filterfunction(_if) : TRUE ) &&
(_fexpr ? __evalcondition(*_if, _fexpr) : TRUE))
(_fexpr ? __evalcondition(*_if, _fexpr, _frefs) : TRUE))
return TRUE;
return FALSE;
@ -1146,6 +1147,7 @@ void TCursor::filter(
{
_filter = fil;
if (_fexpr) delete _fexpr;
_frefs.destroy();
TTypeexp type = (_filter.find('"') != -1) ? _strexpr : _numexpr;
if (_filter.not_empty())
{
@ -1159,6 +1161,20 @@ void TCursor::filter(
}
}
else _fexpr = NULL;
if (_fexpr)
{
const int items = _fexpr->numvar();
for (int i = 0 ; i < items; i++)
{
const TString & vn = _fexpr->varname(i);
if (vn[0] != '#')
{
TFieldref f(vn, 0);
_frefs.add(new TRecfield(_if->curr(f.file()), f.name(), f.from(), f.to()));
}
}
}
}
_keyfrom = kf;
_keyto = kto;
@ -1596,7 +1612,7 @@ int TSorted_cursor::filtercursor(int pagecnt, TRecnotype* page)
file().readat(rec,page[i]);
if (update_relation()) relation()->update();
if ((filterfunction() ? filterfunction()(relation()) : TRUE ) &&
(expression() ? __evalcondition(*relation(), expression()) : TRUE))
(expression() ? __evalcondition(*relation(), expression(), field_refs()) : TRUE))
{
if (np < i) page[np] = page[i];
np++;

View File

@ -243,6 +243,8 @@ class TCursor : public TContainer
TString _keyto;
// @cmember:(INTERNAL) Espressione del filtro relativo
TExpression* _fexpr;
// @cmember:(INTERNAL) Array di fieldref contente i campi interessati al filtro
TArray _frefs;
// @cmember:(INTERNAL) Indica se e' stata messa in attesa (non puo' essere modificato)
bool _frozen;
// @cmember:(INTERNAL) Flag che permette l'update della relazione per l'espressione-filtro
@ -368,6 +370,9 @@ public:
// @cmember Ritorna l'espressione-filtro
TExpression* expression() const
{ return _fexpr; }
// @cmember Ritorna l'array di fieldref contenete i nomi dei campi del filtro
const TArray & field_refs() const
{ return _frefs; }
// @cmember Ritorna la funzione-filtro
FILTERFUNCTION filterfunction() const
{ return _filterfunction; }