From: <vac...@us...> - 2008-12-21 15:55:54
|
Revision: 120 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=120&view=rev Author: vaclavslavik Date: 2008-12-21 15:55:51 +0000 (Sun, 21 Dec 2008) Log Message: ----------- Improved iterators performance by using pool allocator instead of standard operator new to allocate pimpl objects (only if Boost.Pool is available) Modified Paths: -------------- trunk/NEWS trunk/configure.ac trunk/src/Makefile.am trunk/src/libxml/ait_impl.h trunk/src/libxml/attributes.cxx trunk/src/libxml/node.cxx trunk/src/libxml/node_iterator.cxx Added Paths: ----------- trunk/src/libxml/pimpl_base.h Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/NEWS 2008-12-21 15:55:51 UTC (rev 120) @@ -30,6 +30,8 @@ Added new constructor to the xml::node class for creating text nodes, using xml::node::text helper struct. + Improved iterators performance (only if Boost.Pool is available). + Version 0.5.1 Various compilation fixes. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/configure.ac 2008-12-21 15:55:51 UTC (rev 120) @@ -84,6 +84,10 @@ fi +AC_LANG_PUSH([C++]) +AC_CHECK_HEADERS([boost/pool/singleton_pool.hpp]) +AC_LANG_POP([C++]) + dnl === Compiler-specific stuff === if test "x$GCC" == "xyes"; then Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/src/Makefile.am 2008-12-21 15:55:51 UTC (rev 120) @@ -25,6 +25,7 @@ libxml/node_iterator.h \ libxml/node_manip.cxx \ libxml/node_manip.h \ + libxml/pimpl_base.h \ libxml/tree_parser.cxx \ libxml/utility.cxx \ libxml/utility.h Modified: trunk/src/libxml/ait_impl.h =================================================================== --- trunk/src/libxml/ait_impl.h 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/src/libxml/ait_impl.h 2008-12-21 15:55:51 UTC (rev 120) @@ -40,6 +40,8 @@ // xmlwrapp includes #include "xmlwrapp/attributes.h" +#include "pimpl_base.h" + // libxml2 includes #include <libxml/tree.h> @@ -49,7 +51,7 @@ * the class that does all the work behind xml::attributes::iterator and * xml::attributes::const_iterator. */ -class ait_impl { +class ait_impl : public pimpl_base<ait_impl> { public: ait_impl (xmlNodePtr node, xmlAttrPtr prop); ait_impl (const char *name, const char *value, bool); Modified: trunk/src/libxml/attributes.cxx =================================================================== --- trunk/src/libxml/attributes.cxx 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/src/libxml/attributes.cxx 2008-12-21 15:55:51 UTC (rev 120) @@ -37,6 +37,7 @@ // xmlwrapp includes #include "xmlwrapp/attributes.h" #include "ait_impl.h" +#include "pimpl_base.h" // standard includes #include <new> @@ -46,7 +47,7 @@ #include <libxml/tree.h> //#################################################################### -struct xml::attributes::pimpl { +struct xml::attributes::pimpl : public xml::pimpl_base<xml::attributes::pimpl> { //#################################################################### pimpl (void) : owner_(true) { xmlnode_ = xmlNewNode(0, reinterpret_cast<const xmlChar*>("blank")); Modified: trunk/src/libxml/node.cxx =================================================================== --- trunk/src/libxml/node.cxx 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/src/libxml/node.cxx 2008-12-21 15:55:51 UTC (rev 120) @@ -40,6 +40,7 @@ #include "utility.h" #include "ait_impl.h" #include "node_manip.h" +#include "pimpl_base.h" // standard includes #include <cstring> @@ -58,7 +59,7 @@ #include <libxml/parser.h> //#################################################################### -struct xml::node_impl { +struct xml::node_impl : public xml::pimpl_base<xml::node_impl> { //#################################################################### node_impl (void) : xmlnode_(0), owner_(true), attrs_(0) { } Modified: trunk/src/libxml/node_iterator.cxx =================================================================== --- trunk/src/libxml/node_iterator.cxx 2008-12-21 01:38:53 UTC (rev 119) +++ trunk/src/libxml/node_iterator.cxx 2008-12-21 15:55:51 UTC (rev 120) @@ -36,6 +36,7 @@ // definition include #include "node_iterator.h" +#include "pimpl_base.h" // xmlwrapp includes #include "xmlwrapp/node.h" @@ -47,7 +48,7 @@ #include <libxml/tree.h> // xml::node::iterator pimpl -struct xml::nipimpl { +struct xml::nipimpl : public xml::pimpl_base<xml::nipimpl> { node_iterator it; nipimpl (void) {}; Added: trunk/src/libxml/pimpl_base.h =================================================================== --- trunk/src/libxml/pimpl_base.h (rev 0) +++ trunk/src/libxml/pimpl_base.h 2008-12-21 15:55:51 UTC (rev 120) @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2008 Vaclav Slavik (vs...@fa...) + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _xmlwrapp_pimpl_base_h_ +#define _xmlwrapp_pimpl_base_h_ + +#ifdef HAVE_BOOST_POOL_SINGLETON_POOL_HPP + #include <cassert> + #include <boost/pool/singleton_pool.hpp> +#endif // HAVE_BOOST_POOL_SINGLETON_POOL_HPP + +namespace xml +{ + +// Base class for all pimpl classes. Uses custom pool allocator for better +// performance. Usage: derive your class FooImpl from pimpl_base<FooImpl>. +template<typename T> +class pimpl_base +{ +#ifdef HAVE_BOOST_POOL_SINGLETON_POOL_HPP +public: + struct xmlwrapp_pool_tag {}; + + // NB: we can't typedef the pool type as pimpl_base<T> subtype, + // because sizeof(T) is unknown (incomplete type) at this point, + // but it's OK to use the type in implementation of operators + // (compiled only when T, and so sizeof(T), is known) + #define XMLWRAPP_PIMPL_ALLOCATOR_TYPE(T) \ + boost::singleton_pool<xmlwrapp_pool_tag, sizeof(T)> + + static void* operator new(size_t size) + { + assert( size == sizeof(T) ); + return XMLWRAPP_PIMPL_ALLOCATOR_TYPE(T)::malloc(); + } + + static void operator delete(void *ptr, size_t size) + { + assert( size == sizeof(T) ); + if ( ptr ) + XMLWRAPP_PIMPL_ALLOCATOR_TYPE(T)::free(ptr); + } +#endif // HAVE_BOOST_POOL_SINGLETON_POOL_HPP +}; + +} // namespace xml + +#endif // _xmlwrapp_pimpl_base_h_ Property changes on: trunk/src/libxml/pimpl_base.h ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |