You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/08/08 14:20:41 UTC
svn commit: r983398 - in /subversion/branches/performance/subversion:
include/private/svn_temp_serializer.h libsvn_subr/svn_temp_serializer.c
Author: stefan2
Date: Sun Aug 8 12:20:40 2010
New Revision: 983398
URL: http://svn.apache.org/viewvc?rev=983398&view=rev
Log:
Simplify serialization of structures that may be a root structure as well
as being embedded into others. So, no longer require the initialization
routine to be provided with a root structure.
* subversion/libsvn_subr/svn_temp_serializer.c
(svn_temp_serializer__init): don't try to store the root struct if none was given
(store_current_end_pointer): don't try to update the parent reference, if there is none
* subversion/include/private/svn_temp_serializer.h
(svn_temp_serializer__init, svn_temp_serializer__push,
svn_temp_serializer__add_string): explain the new options
Modified:
subversion/branches/performance/subversion/include/private/svn_temp_serializer.h
subversion/branches/performance/subversion/libsvn_subr/svn_temp_serializer.c
Modified: subversion/branches/performance/subversion/include/private/svn_temp_serializer.h
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/include/private/svn_temp_serializer.h?rev=983398&r1=983397&r2=983398&view=diff
==============================================================================
--- subversion/branches/performance/subversion/include/private/svn_temp_serializer.h (original)
+++ subversion/branches/performance/subversion/include/private/svn_temp_serializer.h Sun Aug 8 12:20:40 2010
@@ -46,6 +46,12 @@ typedef struct svn_temp_serializer__cont
* of the actual structure. Due to the generic nature of the init function
* we can't determine the structure size as part of the function.
*
+ * It is possible to specify a @c NULL source_struct in which case the first
+ * call to @ref svn_temp_serializer__push will provide the root struct.
+ * Alternatively, one may even call @ref svn_temp_serializer__add_string
+ * but there is generally no point in doing so because the result will be
+ * simple string object in a @ref svn_stringbuf_t.
+ *
* You may suggest a larger initial buffer size in @a suggested_buffer_size
* to minimize the number of internal buffer re-allocations during the
* serialization process. All allocations will be made from @a pool.
@@ -70,6 +76,11 @@ svn_temp_serializer__init(const void *so
* the serialized structure can be established. @a struct_size must match
* the result of @c sizeof() of the actual structure.
*
+ * Only in case that @ref svn_temp_serializer__init has not been provided
+ * with a root structure and this is the first call after the initialization,
+ * @a source_struct will point to a reference to the root structure instead
+ * of being related to some other.
+ *
* Sub-structures and strings will be added in a FIFO fashion. If you need
* add further sub-structures on the same level, you need to call @ref
* svn_serializer__pop to realign the serialization context.
@@ -95,6 +106,10 @@ svn_temp_serializer__pop(svn_temp_serial
* serialization @a context. @a s must be a reference to the @c char*
* pointer in the original structure so that the correspondence in the
* serialized structure can be established.
+ *
+ * Only in case that @ref svn_temp_serializer__init has not been provided
+ * with a root structure and this is the first call after the initialization,
+ * @a s will not be related to some struct.
*/
void
svn_temp_serializer__add_string(svn_temp_serializer__context_t *context,
Modified: subversion/branches/performance/subversion/libsvn_subr/svn_temp_serializer.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/svn_temp_serializer.c?rev=983398&r1=983397&r2=983398&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/svn_temp_serializer.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/svn_temp_serializer.c Sun Aug 8 12:20:40 2010
@@ -106,18 +106,28 @@ svn_temp_serializer__init(const void *so
? struct_size
: suggested_buffer_size;
- /* create the serialization context and initialize it, including the
- * structure stack */
+ /* create the serialization context and initialize it */
svn_temp_serializer__context_t *context = apr_palloc(pool, sizeof(*context));
context->pool = pool;
context->buffer = svn_stringbuf_create_ensure(init_size, pool);
- context->source = apr_palloc(pool, sizeof(*context->source));
- context->source->source_struct = source_struct;
- context->source->target_offset = 0;
- context->source->upper = NULL;
- /* serialize, i.e. append, the content of the first structure */
- svn_stringbuf_appendbytes(context->buffer, source_struct, struct_size);
+ /* If a source struct has been given, make it the root struct. */
+ if (source_struct)
+ {
+ context->source = apr_palloc(pool, sizeof(*context->source));
+ context->source->source_struct = source_struct;
+ context->source->target_offset = 0;
+ context->source->upper = NULL;
+
+ /* serialize, i.e. append, the content of the first structure */
+ svn_stringbuf_appendbytes(context->buffer, source_struct, struct_size);
+ }
+ else
+ {
+ /* The root struct will be set with the first push() op, or not at all
+ * (in case of a plain string). */
+ context->source = NULL;
+ }
/* done */
return context;
@@ -131,10 +141,17 @@ static void
store_current_end_pointer(svn_temp_serializer__context_t *context,
const void * const * source_pointer)
{
+ apr_size_t offset;
+
+ /* if *source_pointer is the root struct, there will be no parent structure
+ * to relate it to */
+ if (context->source == NULL)
+ return;
+
/* relative position of the serialized pointer to the begin of the buffer */
- apr_size_t offset = (const char *)source_pointer
- - (const char *)context->source->source_struct
- + context->source->target_offset;
+ offset = (const char *)source_pointer
+ - (const char *)context->source->source_struct
+ + context->source->target_offset;
/* use the serialized pointer as a storage for the offset */
apr_size_t *target_string_ptr = (apr_size_t*)(context->buffer->data + offset);