[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/impl.cpp
From: |
Udo Giacomozzi |
Subject: |
[Gnash-commit] gnash ChangeLog server/impl.cpp |
Date: |
Tue, 18 Dec 2007 12:34:46 +0000 |
CVSROOT: /cvsroot/gnash
Module name: gnash
Changes by: Udo Giacomozzi <udog> 07/12/18 12:34:46
Modified files:
. : ChangeLog
server : impl.cpp
Log message:
server/impl.cpp: limit media library size to 8 entries and keep track
of cache hits
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5205&r2=1.5206
http://cvs.savannah.gnu.org/viewcvs/gnash/server/impl.cpp?cvsroot=gnash&r1=1.131&r2=1.132
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnash/gnash/ChangeLog,v
retrieving revision 1.5205
retrieving revision 1.5206
diff -u -b -r1.5205 -r1.5206
--- ChangeLog 18 Dec 2007 11:24:45 -0000 1.5205
+++ ChangeLog 18 Dec 2007 12:34:45 -0000 1.5206
@@ -1,3 +1,8 @@
+2007-12-18 Udo Giacomozzi <address@hidden>
+
+ * server/impl.cpp: limit media library size to 8 entries and keep
+ track of cache hits
+
2007-12-18 Sandro Santilli <address@hidden>
* testsuite/actionscript.all/TextField.as: add a test and check total
Index: server/impl.cpp
===================================================================
RCS file: /cvsroot/gnash/gnash/server/impl.cpp,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -b -r1.131 -r1.132
--- server/impl.cpp 11 Dec 2007 14:36:06 -0000 1.131
+++ server/impl.cpp 18 Dec 2007 12:34:45 -0000 1.132
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-/* $Id: impl.cpp,v 1.131 2007/12/11 14:36:06 strk Exp $ */
+/* $Id: impl.cpp,v 1.132 2007/12/18 12:34:45 udog Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -644,20 +644,40 @@
{
private:
- typedef std::map< std::string, boost::intrusive_ptr<movie_definition> >
container;
+ typedef struct {
+ boost::intrusive_ptr<movie_definition> def;
+ unsigned hit_count;
+ } item;
+
+ typedef std::map< std::string, item > container;
container _map;
+ unsigned _limit;
public:
- MovieLibrary() {}
+ MovieLibrary() :
+ _limit(8)
+ {
+ }
+
+ /// Sets the maximum number of items to hold in the library. When adding new
+ /// items, the one with the least hit count is being removed in that case.
+ /// Zero is a valid limit (disables library).
+ void set_limit(unsigned limit)
+ {
+ _limit = limit;
+ limit_size(_limit);
+ }
bool get(const std::string& key,
boost::intrusive_ptr<movie_definition>* ret)
{
container::iterator it = _map.find(key);
if ( it != _map.end() )
{
- *ret = it->second;
+ *ret = it->second.def;
+ it->second.hit_count++;
+
return true;
}
else
@@ -672,17 +692,59 @@
{
for ( container::const_iterator i=_map.begin(), e=_map.end();
i!=e; ++i)
{
- i->second->setReachable();
+ i->second.def->setReachable();
}
}
#endif
void add(const std::string& key, movie_definition* mov)
{
- _map[key] = mov;
+
+ if (_limit)
+ limit_size(_limit-1);
+ else
+ return; // zero limit, library is a no-op
+
+ item temp;
+
+ temp.def = mov;
+ temp.hit_count=0;
+
+ _map[key] = temp;
}
+
void clear() { _map.clear(); }
+
+private:
+
+ void limit_size(unsigned max)
+ {
+
+ if (max < 1)
+ {
+ clear();
+ return;
+ }
+
+ while (_map.size() > max)
+ {
+
+ // find the item with the worst hit count and remove it
+ container::iterator worst = _map.begin();
+
+ for ( container::iterator i=_map.begin(), e=_map.end(); i!=e; ++i)
+ {
+ if (i->second.hit_count < worst->second.hit_count)
+ worst = i;
+ }
+
+ _map.erase(worst);
+
+ }
+
+ } //limit_size
+
};
static MovieLibrary s_movie_library;