Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65102 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2010-08-29 07:18:54


Author: danieljames
Date: 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
New Revision: 65102
URL: http://svn.boost.org/trac/boost/changeset/65102

Log:
Only stack macros when necessary.

Pushing and popping symbol containers is pretty expensive, so try to do
it less.
Added:
   trunk/tools/quickbook/test/macro.gold (contents, props changed)
   trunk/tools/quickbook/test/macro.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 3 +++
   trunk/tools/quickbook/src/actions_class.cpp | 25 +++++++++++++++++++++++--
   trunk/tools/quickbook/src/actions_class.hpp | 6 +++++-
   trunk/tools/quickbook/test/Jamfile.v2 | 1 +
   4 files changed, 32 insertions(+), 3 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -563,6 +563,7 @@
 
     void macro_definition_action::operator()(iterator first, iterator last) const
     {
+ actions.copy_macros_for_write();
         actions.macro.add(
             actions.macro_id.begin()
           , actions.macro_id.end()
@@ -1329,6 +1330,7 @@
 
         // scope the macros
         string_symbols macro = actions.macro;
+ std::size_t macro_change_depth = actions.macro_change_depth;
         // scope the templates
         //~ template_symbols templates = actions.templates; $$$ fixme $$$
 
@@ -1363,6 +1365,7 @@
 
         // restore the macros
         actions.macro = macro;
+ actions.macro_change_depth = macro_change_depth;
         // restore the templates
         //~ actions.templates = templates; $$$ fixme $$$
     }

Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp (original)
+++ trunk/tools/quickbook/src/actions_class.cpp 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -43,6 +43,7 @@
     // state
         , filename(fs::complete(fs::path(filein_)))
         , outdir(outdir_)
+ , macro_change_depth(0)
         , macro()
         , section_level(0)
         , min_section_level(0)
@@ -209,7 +210,7 @@
             boost::make_tuple(
                 filename
               , outdir
- , macro
+ , macro_change_depth
               , section_level
               , min_section_level
               , section_id
@@ -225,13 +226,33 @@
         list_buffer.push();
         templates.push();
     }
+
+ // Pushing and popping the macro symbol table is pretty expensive, so
+ // instead implement a sort of 'stack on write'. Call this whenever a
+ // change is made to the macro table, and it'll stack the current macros
+ // if necessary. Would probably be better to implement macros in a less
+ // expensive manner.
+ void actions::copy_macros_for_write()
+ {
+ if(macro_change_depth != state_stack.size())
+ {
+ macro_stack.push(macro);
+ macro_change_depth = state_stack.size();
+ }
+ }
 
     void actions::pop()
     {
+ if(macro_change_depth == state_stack.size())
+ {
+ macro = macro_stack.top();
+ macro_stack.pop();
+ }
+
         boost::tie(
             filename
           , outdir
- , macro
+ , macro_change_depth
           , section_level
           , min_section_level
           , section_id

Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp (original)
+++ trunk/tools/quickbook/src/actions_class.hpp 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -68,6 +68,7 @@
     // state
         fs::path filename;
         fs::path outdir;
+ std::size_t macro_change_depth;
         string_symbols macro;
         int section_level;
         int min_section_level;
@@ -78,7 +79,7 @@
         typedef boost::tuple<
             fs::path
           , fs::path
- , string_symbols
+ , std::size_t
           , int
           , int
           , std::string
@@ -87,6 +88,8 @@
         state_tuple;
 
         std::stack<state_tuple> state_stack;
+ // Stack macros separately as copying macros is expensive.
+ std::stack<string_symbols> macro_stack;
 
     // temporary or global state
         std::string element_id;
@@ -111,6 +114,7 @@
         attribute_map attributes;
 
     // push/pop the states and the streams
+ void copy_macros_for_write();
         void push();
         void pop();
 

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -45,6 +45,7 @@
     [ quickbook-test image_1_5 ]
     [ quickbook-test list_test ]
     [ quickbook-test cond_phrase ]
+ [ quickbook-test macro ]
     [ quickbook-test doc-info-1 ]
     [ quickbook-test doc-info-2 ]
     [ quickbook-test doc-info-3 ]

Added: trunk/tools/quickbook/test/macro.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/macro.gold 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="macro_test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Macro Test</title>
+ <para>
+ 1
+ </para>
+ <para>
+ 2
+ </para>
+ <para>
+ two
+ </para>
+</article>

Added: trunk/tools/quickbook/test/macro.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/macro.quickbook 2010-08-29 07:18:51 EDT (Sun, 29 Aug 2010)
@@ -0,0 +1,16 @@
+[article Macro Test
+[quickbook 1.5]
+]
+
+[def one 1]
+
+one
+
+[template foo[]
+
+[def two 2]
+two
+]
+
+[foo]
+two [/This shouldn't expand]
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk