Approximate 20% reduction in runtime on long running scripts, based on profiling data. Reduce number of execution of object cache culling, reduction of copies of the stack and reduction of Boxed_Value copies

This commit is contained in:
Jason Turner
2009-08-05 02:43:13 +00:00
parent 5b424be4ed
commit ba6b392174
3 changed files with 43 additions and 24 deletions

View File

@@ -116,6 +116,11 @@ namespace chaiscript
*/
struct Object_Cache
{
Object_Cache()
: m_cullcount(0)
{
}
boost::shared_ptr<Data> get(Boxed_Value::Void_Type)
{
return boost::shared_ptr<Data> (new Data(
@@ -219,6 +224,12 @@ namespace chaiscript
*/
void cull()
{
++m_cullcount;
if (m_cullcount % 10 != 0)
{
return;
}
std::map<const void *, Data >::iterator itr = m_ptrs.begin();
while (itr != m_ptrs.end())
@@ -235,6 +246,7 @@ namespace chaiscript
}
std::map<const void *, Data > m_ptrs;
int m_cullcount;
};
public:
@@ -472,7 +484,7 @@ namespace chaiscript
template<>
struct Cast_Helper<Boxed_Value>
{
typedef Boxed_Value Result_Type;
typedef const Boxed_Value & Result_Type;
static Result_Type cast(const Boxed_Value &ob)
{
@@ -486,7 +498,7 @@ namespace chaiscript
template<>
struct Cast_Helper<const Boxed_Value &>
{
typedef Boxed_Value Result_Type;
typedef const Boxed_Value & Result_Type;
static Result_Type cast(const Boxed_Value &ob)
{