Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60608 - in trunk/libs/spirit/example/scheme: . detail
From: joel_at_[hidden]
Date: 2010-03-15 00:35:43


Author: djowel
Date: 2010-03-15 00:35:41 EDT (Mon, 15 Mar 2010)
New Revision: 60608
URL: http://svn.boost.org/trac/boost/changeset/60608

Log:
applying Hartmut's fast string trick.
Text files modified:
   trunk/libs/spirit/example/scheme/detail/utree_detail1.hpp | 5 +++--
   trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp | 15 ++++++++-------
   trunk/libs/spirit/example/scheme/simple_print.hpp | 2 +-
   3 files changed, 12 insertions(+), 10 deletions(-)

Modified: trunk/libs/spirit/example/scheme/detail/utree_detail1.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/detail/utree_detail1.hpp (original)
+++ trunk/libs/spirit/example/scheme/detail/utree_detail1.hpp 2010-03-15 00:35:41 EDT (Mon, 15 Mar 2010)
@@ -82,8 +82,9 @@
     // meant to be used stand-alone. This is the internal data representation
     // of strings in our utree. This is deliberately a POD to allow it to be
     // placed in a union. This POD fast string specifically utilizes
- // (sizeof(double) * 2) - (2 * sizeof(char)). In a 32 bit system, this is
- // 14 bytes. The two extra bytes are used by utree to store management info.
+ // (sizeof(list) * alignment_of(list)) - (2 * sizeof(char)). In a 32 bit
+ // system, this is 14 bytes. The two extra bytes are used by utree to store
+ // management info.
     //
     // It is a const string (i.e. immutable). It stores the characters directly
     // if possible and only uses the heap if the string does not fit. Null

Modified: trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp (original)
+++ trunk/libs/spirit/example/scheme/detail/utree_detail2.hpp 2010-03-15 00:35:41 EDT (Mon, 15 Mar 2010)
@@ -25,7 +25,7 @@
             || get_type() == utree_type::heap_string_type);
 
         if (get_type() == utree_type::small_string_type)
- return buff[0];
+ return small_string_size - buff[small_string_size - 1];
         else
             return heap.size;
     }
@@ -36,7 +36,7 @@
             || get_type() == utree_type::heap_string_type);
 
         if (get_type() == utree_type::small_string_type)
- return buff + 1;
+ return buff;
         else
             return heap.str;
     }
@@ -48,16 +48,16 @@
         char* str;
         if (size < small_string_size)
         {
- // if it fits, store it in-situ; the first byte
- // is the length of the string.
- str = buff + 1;
- buff[0] = size;
+ // if it fits, store it in-situ; small_string_size minus the length
+ // of the string is placed in buff[small_string_size - 1]
+ str = buff;
+ buff[small_string_size - 1] = small_string_size - size;
             set_type(utree_type::small_string_type);
         }
         else
         {
             // else, store it in the heap
- str = new char[size];
+ str = new char[size + 1]; // add one for the null char
             heap.str = str;
             heap.size = size;
             set_type(utree_type::heap_string_type);
@@ -66,6 +66,7 @@
         {
             *str++ = *f++;
         }
+ *str = '\0'; // add the null char
     }
 
     inline void fast_string::swap(fast_string& other)

Modified: trunk/libs/spirit/example/scheme/simple_print.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/simple_print.hpp (original)
+++ trunk/libs/spirit/example/scheme/simple_print.hpp 2010-03-15 00:35:41 EDT (Mon, 15 Mar 2010)
@@ -60,7 +60,7 @@
             {
                 out << "b"; ++i;
                 out.width(2);
- out.setf('0');
+ out.fill('0');
                 for (; i != range.end(); ++i)
                     out << std::hex << int((unsigned char)*i);
                 out << std::dec;


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