From 43de9ebbbfc11005fc1acfe7f6e85cf5112740a4 Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 5 Dec 2005 16:13:12 +0000 Subject: [PATCH] avoid unneeded getDoc(0) + normalize private var names --- src/query/docseq.cpp | 51 +++++++++++++++++++++++--------------------- src/query/docseq.h | 21 +++++++++--------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/query/docseq.cpp b/src/query/docseq.cpp index d304be3e..b5aa4223 100644 --- a/src/query/docseq.cpp +++ b/src/query/docseq.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: docseq.cpp,v 1.3 2005-12-05 12:02:01 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: docseq.cpp,v 1.4 2005-12-05 16:13:12 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -8,61 +8,64 @@ static char rcsid[] = "@(#$Id: docseq.cpp,v 1.3 2005-12-05 12:02:01 dockes Exp $ bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh) { if (sh) sh->erase(); - return db ? db->getDoc(num, doc, percent) : false; + return m_db ? m_db->getDoc(num, doc, percent) : false; } int DocSequenceDb::getResCnt() { - if (!db) + if (!m_db) return -1; // Need to fetch one document before we can get the result count - Rcl::Doc doc; - int percent; - db->getDoc(0, doc, &percent); - return db->getResCnt(); + if (m_rescnt < 0) { + Rcl::Doc doc; + int percent; + m_db->getDoc(0, doc, &percent); + m_rescnt= m_db->getResCnt(); + } + return m_rescnt; } bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh) { // Retrieve history list - if (!hist) + if (!m_hist) return false; - if (hlist.empty()) - hlist = hist->getDocHistory(); + if (m_hlist.empty()) + m_hlist = m_hist->getDocHistory(); - if (num < 0 || num >= (int)hlist.size()) + if (num < 0 || num >= (int)m_hlist.size()) return false; int skip; - if (prevnum >= 0 && num >= prevnum) { - skip = num - prevnum; + if (m_prevnum >= 0 && num >= m_prevnum) { + skip = num - m_prevnum; } else { skip = num; - it = hlist.begin(); - prevtime = -1; + m_it = m_hlist.begin(); + m_prevtime = -1; } - prevnum = num; + m_prevnum = num; while (skip--) - it++; + m_it++; if (percent) *percent = 100; if (sh) { - if (prevtime < 0 || abs(prevtime - (*it).unixtime) > 86400) { - prevtime = it->unixtime; - time_t t = (time_t)(it->unixtime); + if (m_prevtime < 0 || abs(m_prevtime - m_it->unixtime) > 86400) { + m_prevtime = m_it->unixtime; + time_t t = (time_t)(m_it->unixtime); *sh = string(ctime(&t)); // Get rid of the final \n in ctime sh->erase(sh->length()-1); } else sh->erase(); } - return db->getDoc((*it).fn, (*it).ipath, doc); + return m_db->getDoc(m_it->fn, m_it->ipath, doc); } int DocSequenceHistory::getResCnt() { - if (hlist.empty()) - hlist = hist->getDocHistory(); - return hlist.size(); + if (m_hlist.empty()) + m_hlist = m_hist->getDocHistory(); + return m_hlist.size(); } diff --git a/src/query/docseq.h b/src/query/docseq.h index dbb997d9..28554956 100644 --- a/src/query/docseq.h +++ b/src/query/docseq.h @@ -1,6 +1,6 @@ #ifndef _DOCSEQ_H_INCLUDED_ #define _DOCSEQ_H_INCLUDED_ -/* @(#$Id: docseq.h,v 1.2 2005-11-28 15:31:01 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: docseq.h,v 1.3 2005-12-05 16:13:12 dockes Exp $ (C) 2004 J.F.Dockes */ #include "rcldb.h" #include "history.h" @@ -23,33 +23,34 @@ class DocSequence { to make sense */ class DocSequenceDb : public DocSequence { public: - DocSequenceDb(Rcl::Db *d) : db(d) {} + DocSequenceDb(Rcl::Db *d) : m_db(d), m_rescnt(-1) {} virtual ~DocSequenceDb() {} virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0); virtual int getResCnt(); virtual std::string title() {return string("Query results");} private: - Rcl::Db *db; + Rcl::Db *m_db; + int m_rescnt; }; /** A DocSequence coming from the history file */ class DocSequenceHistory : public DocSequence { public: DocSequenceHistory(Rcl::Db *d, RclDHistory *h) - : db(d), hist(h), prevnum(-1), prevtime(-1) {} + : m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {} virtual ~DocSequenceHistory() {} virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0); virtual int getResCnt(); virtual std::string title() {return string("Document history");} private: - Rcl::Db *db; - RclDHistory *hist; - int prevnum; - long prevtime; + Rcl::Db *m_db; + RclDHistory *m_hist; + int m_prevnum; + long m_prevtime; - std::list hlist; - std::list::const_iterator it; + std::list m_hlist; + std::list::const_iterator m_it; }; #endif /* _DOCSEQ_H_INCLUDED_ */