[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r11702: Cache resource list size so
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r11702: Cache resource list size so deciding whether or not to run the collection cycle runs in constant time. |
Date: |
Wed, 16 Dec 2009 20:46:46 +0100 |
User-agent: |
Bazaar (2.0.2) |
------------------------------------------------------------
revno: 11702
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Wed 2009-12-16 20:46:46 +0100
message:
Cache resource list size so deciding whether or not to run the collection
cycle runs in constant time.
modified:
libbase/GC.cpp
libbase/GC.h
=== modified file 'libbase/GC.cpp'
--- a/libbase/GC.cpp 2009-12-15 23:54:32 +0000
+++ b/libbase/GC.cpp 2009-12-16 19:46:46 +0000
@@ -93,12 +93,11 @@
if ( ! res->isReachable() )
{
#if GNASH_GC_DEBUG > 1
- log_debug(_("GC: recycling object %p (%s)"),
- res, typeName(*res).c_str());
+ log_debug(_("GC: recycling object %p (%s)"), res,
typeName(*res));
#endif
++deleted;
delete res;
- i = _resList.erase(i);
+ i = _resList.erase(i); // _resListSize updated at end
of loop
}
else
{
@@ -107,6 +106,8 @@
}
}
+ _resListSize -= deleted;
+
return deleted;
}
@@ -142,7 +143,7 @@
// runtime analisys
//
- size_t curResCount = _resList.size(); // this is O(n) on GNU stdc++ lib
!
+ size_t curResCount = _resListSize;
if ( curResCount < _lastResCount + maxNewCollectablesCount )
{
#if GNASH_GC_DEBUG > 1
@@ -181,7 +182,7 @@
deleted, _lastResCount);
#endif
- //assert(_lastResCount == _resList.size()); // again O(n)...
+ //assert(_lastResCount == _resList.size()); // O(n)...
}
=== modified file 'libbase/GC.h'
--- a/libbase/GC.h 2009-12-15 23:54:32 +0000
+++ b/libbase/GC.h 2009-12-16 19:46:46 +0000
@@ -41,7 +41,7 @@
// 2 - print a message for every GcResource being registered and being
deleted
// 3 - print info about the mark scan
//
-//#define GNASH_GC_DEBUG 1
+#define GNASH_GC_DEBUG 1
#ifdef GNASH_GC_DEBUG
# include "log.h"
@@ -237,9 +237,9 @@
//assert(std::find(_resList.begin(), _resList.end(), item) ==
_resList.end());
#endif
- _resList.push_back(item);
+ _resList.push_back(item); ++_resListSize;
#if GNASH_GC_DEBUG > 1
- log_debug(_("GC %p: collectable %p added, num collectables:
%d"), (void*)this, (void*)item, _resList.size());
+ log_debug(_("GC: collectable %p added, num collectables: %d"),
item, _resListSize);
#endif
}
@@ -264,6 +264,7 @@
/// Create a garbage collector, using the given root
GC(GcRoot& root)
:
+ _resListSize(0),
_root(root),
_lastResCount(0)
#ifdef GNASH_GC_DEBUG
@@ -296,8 +297,15 @@
///
size_t cleanUnreachable();
+ /// List of collectable resources
ResList _resList;
+ // Size of the list above, to avoid the
+ // cost of computing it ..
+ // .. this is O(n) on GNU stdc++ lib !
+ //
+ ResList::size_type _resListSize;
+
GcRoot& _root;
static GC* _singleton;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r11702: Cache resource list size so deciding whether or not to run the collection cycle runs in constant time.,
Sandro Santilli <=