Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65104 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2010-08-29 07:20:59


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

Log:
Use C strings in position_iterator.

Copying std::string in position_iterator was taking up a lot of
execution time.
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 44 +++++++++++++++++++++++----------------
   trunk/tools/quickbook/src/actions.hpp | 4 ++
   trunk/tools/quickbook/src/code_snippet.cpp | 5 +--
   trunk/tools/quickbook/src/quickbook.cpp | 14 +++++-------
   trunk/tools/quickbook/src/template_stack.hpp | 29 +++++++++++++++++++++++++
   5 files changed, 65 insertions(+), 31 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:20:57 EDT (Sun, 29 Aug 2010)
@@ -43,7 +43,7 @@
     // Handles line-breaks (DEPRECATED!!!)
     void break_action::operator()(iterator first, iterator) const
     {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
         detail::outwarn(pos.file,pos.line) << "in column:" << pos.column << ", "
             << "[br] and \\n are deprecated" << ".\n";
         phrase << break_mark;
@@ -51,7 +51,7 @@
 
     void error_action::operator()(iterator first, iterator /*last*/) const
     {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
         detail::outerr(pos.file,pos.line)
             << "Syntax Error near column " << pos.column << ".\n";
         ++error_count;
@@ -271,7 +271,7 @@
 
         if (mark != list_marks.top().first) // new_indent == list_indent
         {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Illegal change of list style near column " << pos.column << ".\n";
             detail::outwarn(pos.file,pos.line)
@@ -290,7 +290,7 @@
 
     void unexpected_char::operator()(iterator first, iterator last) const
     {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
 
         detail::outwarn(pos.file, pos.line)
             << "in column:" << pos.column
@@ -440,7 +440,7 @@
 
     void attribute_action::operator()(iterator first, iterator last) const
     {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
 
         if (!attributes.insert(
                 attribute_map::value_type(attribute_name, std::string(first, last))
@@ -578,7 +578,7 @@
                 std::string(first, last), first.get_position(),
                 actions.template_block, &actions.templates.top_scope())))
         {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Template Redefinition: " << actions.template_identifier << std::endl;
             ++actions.error_count;
@@ -648,7 +648,7 @@
         bool break_arguments(
             std::vector<template_body>& args
           , std::vector<std::string> const& params
- , boost::spirit::classic::file_position const& pos
+ , position const& pos
         )
         {
             // Quickbook 1.4-: If there aren't enough parameters seperated by
@@ -669,7 +669,8 @@
                     // arguments, or if there are no more spaces left.
 
                     template_body& body = args.back();
- iterator begin(body.content.begin(), body.content.end(), body.position.file);
+ iterator begin(body.content.begin(), body.content.end(),
+ position(body.position.file.c_str(), body.position.line, body.position.column));
                     iterator end(body.content.end(), body.content.end());
                     
                     iterator l_pos = find_first_seperator(begin, end);
@@ -706,7 +707,7 @@
             std::vector<template_body>& args
           , std::vector<std::string> const& params
           , template_scope const& scope
- , boost::spirit::classic::file_position const& pos
+ , position const& pos
           , quickbook::actions& actions
         )
         {
@@ -758,7 +759,8 @@
                 simple_phrase_grammar phrase_p(actions);
 
                 // do a phrase level parse
- iterator first(body.content.begin(), body.content.end(), body.position);
+ iterator first(body.content.begin(), body.content.end(),
+ position(body.position.file.c_str(), body.position.line, body.position.column));
                 iterator last(body.content.end(), body.content.end());
                 bool r = call_parse(first, last, phrase_p).full;
                 actions.phrase.swap(result);
@@ -773,7 +775,8 @@
                 // the need to check for end of file in the grammar.
                 
                 std::string content = body.content + "\n\n";
- iterator first(content.begin(), content.end(), body.position);
+ iterator first(content.begin(), content.end(),
+ position(body.position.file.c_str(), body.position.line, body.position.column));
                 iterator last(content.end(), content.end());
                 bool r = call_parse(first, last, block_p).full;
                 actions.inside_paragraph();
@@ -805,7 +808,7 @@
         std::string identifier;
         std::swap(args, actions.template_args);
         std::swap(identifier, actions.template_identifier);
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
 
         ++actions.template_depth;
         if (actions.template_depth > actions.max_template_depth)
@@ -905,7 +908,7 @@
 
             if (!parse_template(symbol->body, actions.template_escape, result, actions))
             {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
                 detail::outerr(pos.file,pos.line)
                     << "Expanding "
                     << (symbol->body.is_block ? "block" : "phrase")
@@ -923,7 +926,7 @@
 
             if (actions.section_level != actions.min_section_level)
             {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
                 detail::outerr(pos.file,pos.line)
                     << "Mismatched sections in template " << identifier << std::endl;
                 actions.pop(); // restore the actions' states
@@ -951,7 +954,12 @@
                 if(!r)
                 {
                     detail::outerr(c.position.file, c.position.line)
- << "Expanding callout." << std::endl;
+ << "Expanding callout." << std::endl
+ << "------------------begin------------------" << std::endl
+ << c.content
+ << std::endl
+ << "------------------end--------------------" << std::endl
+ ;
                     ++actions.error_count;
                     return;
                 }
@@ -1176,7 +1184,7 @@
     {
         if (section_level <= min_section_level)
         {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Mismatched [endsect] near column " << pos.column << ".\n";
             ++error_count;
@@ -1201,7 +1209,7 @@
     
     void element_id_warning_action::operator()(iterator first, iterator) const
     {
- boost::spirit::classic::file_position const pos = first.get_position();
+ position const pos = first.get_position();
         detail::outwarn(pos.file,pos.line) << "Empty id.\n";
     }
 
@@ -1292,7 +1300,7 @@
             ts.parent = &actions.templates.top_scope();
             if (!actions.templates.add(ts))
             {
- boost::spirit::classic::file_position const pos = ts.body.position;
+ cl::file_position const pos = ts.body.position;
                 detail::outerr(pos.file, pos.line)
                     << "Template Redefinition: " << tname << std::endl;
                 ++actions.error_count;

Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2010-08-29 07:20:57 EDT (Sun, 29 Aug 2010)
@@ -35,7 +35,9 @@
     namespace cl = boost::spirit::classic;
     namespace fs = boost::filesystem;
 
- typedef cl::position_iterator<std::string::const_iterator> iterator;
+ typedef cl::position_iterator<std::string::const_iterator,
+ cl::file_position_base<char const*> > iterator;
+ typedef cl::file_position_base<char const*> position;
     typedef cl::symbols<std::string> string_symbols;
     typedef std::map<std::string, std::string> attribute_map;
 

Modified: trunk/tools/quickbook/src/code_snippet.cpp
==============================================================================
--- trunk/tools/quickbook/src/code_snippet.cpp (original)
+++ trunk/tools/quickbook/src/code_snippet.cpp 2010-08-29 07:20:57 EDT (Sun, 29 Aug 2010)
@@ -248,9 +248,8 @@
         if (err != 0)
             return err; // return early on error
 
- typedef position_iterator<std::string::const_iterator> iterator_type;
- iterator_type first(code.begin(), code.end(), file);
- iterator_type last(code.end(), code.end());
+ iterator first(code.begin(), code.end(), file.c_str());
+ iterator last(code.end(), code.end());
 
         size_t fname_len = file.size();
         bool is_python = fname_len >= 3

Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2010-08-29 07:20:57 EDT (Sun, 29 Aug 2010)
@@ -53,9 +53,8 @@
                 end = preset_defines.end();
                 it != end; ++it)
         {
- typedef position_iterator<std::string::const_iterator> iterator_type;
- iterator_type first(it->begin(), it->end(), "command line parameter");
- iterator_type last(it->end(), it->end());
+ iterator first(it->begin(), it->end(), "command line parameter");
+ iterator last(it->end(), it->end());
 
             call_parse(first, last, grammar);
             // TODO: Check result?
@@ -81,12 +80,11 @@
             return err;
         }
 
- typedef position_iterator<std::string::const_iterator> iterator_type;
- iterator_type first(storage.begin(), storage.end(), filein_);
- iterator_type last(storage.end(), storage.end());
+ iterator first(storage.begin(), storage.end(), filein_);
+ iterator last(storage.end(), storage.end());
 
         doc_info_grammar l(actor);
- parse_info<iterator_type> info = call_parse(first, last, l);
+ parse_info<iterator> info = call_parse(first, last, l);
 
         if (info.hit || ignore_docinfo)
         {
@@ -102,7 +100,7 @@
 
         if (!info.full)
         {
- file_position const pos = info.stop.get_position();
+ position const pos = info.stop.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Syntax Error near column " << pos.column << ".\n";
             ++actor.error_count;

Modified: trunk/tools/quickbook/src/template_stack.hpp
==============================================================================
--- trunk/tools/quickbook/src/template_stack.hpp (original)
+++ trunk/tools/quickbook/src/template_stack.hpp 2010-08-29 07:20:57 EDT (Sun, 29 Aug 2010)
@@ -25,7 +25,7 @@
     {
         template_body(
                 std::string const& content,
- boost::spirit::classic::file_position position,
+ boost::spirit::classic::file_position const& position,
                 bool is_block
             )
             : content(content)
@@ -33,8 +33,21 @@
             , is_block(is_block)
         {
         }
+
+ template_body(
+ std::string const& content,
+ boost::spirit::classic::file_position_base<char const*> const& position,
+ bool is_block
+ )
+ : content(content)
+ , position(position.file, position.line, position.column)
+ , is_block(is_block)
+ {
+ }
     
         std::string content;
+ // Note: Using file_position to store the filename after the file
+ // has been closed.
         boost::spirit::classic::file_position position;
         bool is_block;
     };
@@ -57,6 +70,20 @@
            , callout(false)
            , callouts() {}
 
+ template_symbol(
+ std::string const& identifier,
+ std::vector<std::string> const& params,
+ std::string const& body,
+ boost::spirit::classic::file_position_base<char const*> const& position,
+ bool is_block,
+ template_scope const* parent = 0)
+ : identifier(identifier)
+ , params(params)
+ , body(body, position, is_block)
+ , parent(parent)
+ , callout(false)
+ , callouts() {}
+
         std::string identifier;
         std::vector<std::string> params;
         template_body body;


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