John Levon wrote: >oh, and ben says you all suck for not applying his mmap deptable patch [1] > >john >[1] not really > Um, I was just wondering if it went to > /dev/null. Here it is again, for 1.2cvs.
This patch fixes errors which will cause excessive numbers of LaTeX runs, and makes the new deptable file compatible with previous versions of Lyx (and vice versa). Ben.
--- lyx-devel-orig/src/ChangeLog Wed Dec 12 09:26:32 2001 +++ lyx-devel/src/ChangeLog Wed Dec 12 09:24:51 2001 @@ -1,3 +1,9 @@ +2001-12-12 Ben Stanley <[EMAIL PROTECTED]> + + * DepTable.h + * DepTable.C: Implement mtime checking to reduce time + spent doing CRCs. + 2001-12-10 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * tabular-old.C (getTokenValue): --- lyx-devel-orig/src/DepTable.h Tue Nov 27 13:56:55 2001 +++ lyx-devel/src/DepTable.h Fri Dec 7 13:01:06 2001 @@ -8,6 +8,7 @@ * * This file is Copyright 1996-2001 * Lars Gullik Bjønnes + * Ben Stanley * * ====================================================== */ @@ -29,9 +30,7 @@ filename. Should we insert files with .sty .cls etc as extension? */ void insert(string const & f, - bool upd = false, - unsigned long one = 0, - unsigned long two = 0); + bool upd = false); /// void update(); @@ -47,14 +46,23 @@ bool extchanged(string const & ext) const; /// bool exist(string const & fil) const; + /// returns true if any files with ext exist + bool ext_exist(string const& ext) const; /// void remove_files_with_extension(string const &); + /// + void remove_file(string const &); private: /// struct dep_info { - unsigned long first; - unsigned long second; - long mtime; + /// Previously calculated CRC value + unsigned long crc_prev; + /// Current CRC value - only re-computed if mtime has changed. + unsigned long crc_cur; + /// mtime from last time current CRC was calculated. + long mtime_cur; + /// + bool changed() const; }; /// typedef std::map<string, dep_info> DepList; @@ -63,3 +71,4 @@ }; #endif + --- lyx-devel-orig/src/DepTable.C Thu Dec 6 10:57:59 2001 +++ lyx-devel/src/DepTable.C Wed Dec 12 08:31:26 2001 @@ -7,6 +7,7 @@ * * This file is Copyright 1996-2001 * Lars Gullik Bjønnes + * Ben Stanley * * ====================================================== */ @@ -35,69 +36,78 @@ using std::ifstream; using std::endl; +inline bool DepTable::dep_info::changed() const +{ + return crc_prev != crc_cur && crc_cur != 0; +} + void DepTable::insert(string const & fi, - bool upd, - unsigned long one, - unsigned long two) + bool upd) { // not quite sure if this is the correct place for MakeAbsPath string f = MakeAbsPath(fi); if (deplist.find(f) == deplist.end()) { - long mtime = 0; + dep_info di; + di.crc_prev = 0; if (upd) { - one = two; - two = lyx::sum(f); + lyxerr[Debug::DEPEND] << " CRC..." << flush; + di.crc_cur = lyx::sum(f); + lyxerr[Debug::DEPEND] << "done." << endl; struct stat f_info; stat(fi.c_str(), &f_info); - mtime = f_info.st_mtime; + di.mtime_cur = f_info.st_mtime; + } else { + di.crc_cur = 0; + di.mtime_cur = 0; } - dep_info di; - di.first = one; - di.second = two; - di.mtime = mtime; -#if 0 - deplist[f] = make_pair(one, two); -#else deplist[f] = di; -#endif + } else { + lyxerr[Debug::DEPEND] << " Already in DepTable" << endl; } } void DepTable::update() { - for (DepList::iterator itr = deplist.begin(); - itr != deplist.end(); - ++itr) { - unsigned long const one = itr->second.second; - unsigned long two = one; - long mtime = itr->second.mtime; - struct stat f_info; - stat(itr->first.c_str(), &f_info); + lyxerr[Debug::DEPEND] << "Updating DepTable..." << endl; + time_t start_time = time(0); - if (mtime != f_info.st_mtime) { - two = lyx::sum(itr->first); - mtime = f_info.st_mtime; + DepList::iterator itr = deplist.begin(); + while (itr != deplist.end()) { + dep_info &di = itr->second; + + struct stat f_info; + if (0 == stat(itr->first.c_str(), &f_info) ) { + if (di.mtime_cur == f_info.st_mtime) { + di.crc_prev = di.crc_cur; + lyxerr[Debug::DEPEND] << itr->first << " same mtime"; + } else { + di.crc_prev = di.crc_cur; + lyxerr[Debug::DEPEND] << itr->first << " CRC... "; + di.crc_cur = lyx::sum(itr->first); + lyxerr[Debug::DEPEND] << "done"; + } + } else { + // file doesn't exist + // remove stale files - if it's re-created, it + // will be re-inserted by deplog. + lyxerr[Debug::DEPEND] << itr->first + << " doesn't exist. removing from DepTable." << endl; + DepList::iterator doomed = itr++; + deplist.erase(doomed); + continue; } -#if 0 - itr->second = make_pair(one, two); -#else - dep_info di; - di.first = one; - di.second = two; - di.mtime = mtime; - - itr->second = di; -#endif if (lyxerr.debugging(Debug::DEPEND)) { - lyxerr << "Update dep: " << itr->first << " " - << one << " " << two; - if (one != two) + if (di.changed()) lyxerr << " +"; lyxerr << endl; } + ++itr; } + time_t time_sec = time(0) - start_time; + lyxerr[Debug::DEPEND] << "Finished updating DepTable (" + << time_sec << " sec)." << endl; } @@ -106,7 +116,7 @@ for (DepList::const_iterator cit = deplist.begin(); cit != deplist.end(); ++cit) { - if ((*cit).second.first != cit->second.second) return true; + if ((*cit).second.changed()) return true; } return false; } @@ -118,8 +128,7 @@ string fil = MakeAbsPath(f); DepList::const_iterator cit = deplist.find(fil); if (cit != deplist.end()) { - if (cit->second.first != cit->second.second - && cit->second.second != 0) + if (cit->second.changed()) return true; } return false; @@ -132,7 +141,7 @@ cit != deplist.end(); ++cit) { if (suffixIs(cit->first, ext)) { - if (cit->second.first != cit->second.second) + if (cit->second.changed()) return true; } } @@ -140,24 +149,53 @@ } -bool DepTable::exist(string const & fil) const +bool DepTable::ext_exist(const string& ext ) const { - DepList::const_iterator cit = deplist.find(fil); - if (cit != deplist.end()) return true; + for (DepList::const_iterator cit = deplist.begin(); + cit != deplist.end(); ++cit ) { + + if ( suffixIs(cit->first, ext) ) { + return true; + } + } return false; } +bool DepTable::exist(string const & fil) const +{ + return deplist.find(fil) != deplist.end(); +} + void DepTable::remove_files_with_extension(string const & suf) { - DepList tmp; - // we want const_iterator (Lgb) - for (DepList::iterator cit = deplist.begin(); - cit != deplist.end(); ++cit) { - if (!suffixIs(cit->first, suf)) - tmp[cit->first] = cit->second; + DepList::iterator cit = deplist.begin(); + while (cit != deplist.end()) { + if (suffixIs(cit->first, suf)) { + // Can't erase the current iterator, but we can increment and +then erase. + // deplist is a map so only the erased iterator is invalidated. + DepList::iterator doomed = cit++; + deplist.erase(doomed); + continue; + } + cit++; + } +} + + +void DepTable::remove_file(string const & filename) +{ + DepList::iterator cit = deplist.begin(); + while (cit != deplist.end()) { + if (OnlyFilename(cit->first) == filename) { + // Can't erase the current iterator, but we can increment and +then erase. + // deplist is a map so only the erased iterator is invalidated. + DepList::iterator doomed = cit++; + deplist.erase(doomed); + continue; + } + cit++; } - deplist.swap(tmp); } @@ -167,16 +205,16 @@ for (DepList::const_iterator cit = deplist.begin(); cit != deplist.end(); ++cit) { if (lyxerr.debugging(Debug::DEPEND)) { + // Store the second (most recently calculated) CRC value. + // The older one is effectively set to 0 upon re-load. lyxerr << "Write dep: " << cit->first << " " - << cit->second.first << " " - << cit->second.second << " " - << cit->second.mtime << endl; + << cit->second.crc_cur << " " + << cit->second.mtime_cur << endl; } ofs << cit->first << " " - << cit->second.first << " " - << cit->second.second << " " - << cit->second.mtime << endl; + << cit->second.crc_cur << " " + << cit->second.mtime_cur << endl; } } @@ -185,26 +223,18 @@ { ifstream ifs(f.c_str()); string nome; - unsigned long one = 0; - unsigned long two = 0; - unsigned long mtime = 0; + dep_info di; + // This doesn't change through the loop. + di.crc_prev = 0; - while (ifs >> nome >> one >> two >> mtime) { + while (ifs >> nome >> di.crc_cur >> di.mtime_cur) { if (lyxerr.debugging(Debug::DEPEND)) { lyxerr << "Read dep: " << nome << " " - << one << " " - << two << " " - << mtime << endl; + << di.crc_cur << " " + << di.mtime_cur << endl; } - dep_info di; - di.first = one; - di.second = two; - di.mtime = mtime; -#if 0 - deplist[nome] = make_pair(one, two); -#else deplist[nome] = di; -#endif } } +