From 2c1591e4100490ec4b0cbfd76572a22d6752b139 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 27 Jun 2002 13:01:31 +0000 Subject: [PATCH] shorten filenames a bit git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4497 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formula.C | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 88dea2d1ec..01c3f227e3 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -460,6 +460,26 @@ void InsetFormula::init() } +// built some unique filename +string constructFileName(string const & data) +{ + typedef std::map cache_type; + static cache_type theCache; + static int theCounter = 0; + + int number; + cache_type::const_iterator it = theCache.find(data); + if (it == theCache.end()) + number = theCache[data] = theCounter++; + else + number = it->second; + + ostringstream os; + os << number; + return os.str(); +} + + void InsetFormula::updatePreview() const { // nothing to be done if no preview requested @@ -472,21 +492,16 @@ void InsetFormula::updatePreview() const WriteStream wi(ls, false, false); par_->write(wi); string const data = ls.str(); - - // built some unique filename - ostringstream os; - os << "preview_"; - for (string::const_iterator it = data.begin(); it != data.end(); ++it) - os << char('A' + (*it & 15)) << char('a' + (*it >> 4)); - string base = os.str(); - string dir = OnlyPath(lyx::tempName()); - string file = dir + base + ".lyxpreview"; + string const base = constructFileName(data); + string const dir = OnlyPath(lyx::tempName()); + string const file = dir + base + ".lyxpreview"; // everything is fine already if (loader_.filename() == file) return; // the real work starts + //lyxerr << "### updatePreview() called for " << file << "\n"; std::ofstream of(file.c_str()); of << "\\batchmode" << "\\documentclass{article}" @@ -500,4 +515,6 @@ void InsetFormula::updatePreview() const // now we are done, start actual loading we will get called back via // InsetFormula::statusChanged() if this is finished - loader_.reset(file); } + loader_.reset(file); +} + -- 2.39.2