[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Extreme pickyness or just subversion coding standards?

From: Erik Huelsmann <e.huelsmann_at_gmx.net>
Date: 2003-12-02 21:12:29 CET

The following patch is ready to be committed. Is it extreme pickyness (and
overkill) or is this what is to be expected by our coding standards?

bye,

Erik.

Log:
[[[
Extreme pickyness?
 
* subversion/libsvn_subr/hash.c (svn_hash_write):
  Eliminate allocation of fixed array on the stack.
  Use apr_psprintf instead of stdio's sprintf.
  Use iteration pool as required by pool conventions
]]]

Index: subversion/libsvn_subr/hash.c
===================================================================
--- subversion/libsvn_subr/hash.c (revision 7904)
+++ subversion/libsvn_subr/hash.c (working copy)
@@ -18,7 +18,6 @@
  
  
 
-#include <stdio.h> /* for sprintf() */
 #include <stdlib.h>
 #include <apr_pools.h>
 #include <apr_hash.h>
@@ -28,8 +27,8 @@
 #include "svn_error.h"
 #include "svn_hash.h"
 #include "svn_io.h"
+#include "svn_pools.h"
  
-
 
  
 /*
@@ -79,46 +78,53 @@
                 apr_pool_t *pool)
 {
   apr_hash_index_t *this; /* current hash entry */
- char buf[SVN_KEYLINE_MAXLEN];
+ apr_pool_t *iterpool;
  
+ iterpool = svn_pool_create (pool);
+
   for (this = apr_hash_first (pool, hash); this; this = apr_hash_next
(this))
     {
       const void *key;
       void *val;
       apr_ssize_t keylen;
- int bytes_used;
+ const char* buf;
       const svn_string_t *value;
  
+ svn_pool_clear (iterpool);
+
       /* Get this key and val. */
       apr_hash_this (this, &key, &keylen, &val);
  
       /* Output name length, then name. */
+ SVN_ERR (svn_io_file_write_full (destfile, "K ", 2, NULL, iterpool));
  
- SVN_ERR (svn_io_file_write_full (destfile, "K ", 2, NULL, pool));
+ buf = apr_psprintf (iterpool, "%" APR_SSIZE_T_FMT, keylen);
+ SVN_ERR (svn_io_file_write_full (destfile,
+ buf, strlen (buf), NULL, iterpool));
+ SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, iterpool));
  
- sprintf (buf, "%" APR_SSIZE_T_FMT "%n", keylen, &bytes_used);
- SVN_ERR (svn_io_file_write_full (destfile, buf, bytes_used, NULL,
pool));- SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, pool));
-
       SVN_ERR (svn_io_file_write_full (destfile,
                                        (const char *) key, keylen,
- NULL, pool));
- SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, pool));
+ NULL, iterpool));
+ SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, iterpool));
  
       /* Output value length, then value. */
       value = val;
  
       SVN_ERR (svn_io_file_write_full (destfile, "V ", 2, NULL, pool));
  
- sprintf (buf, "%" APR_SIZE_T_FMT "%n", value->len, &bytes_used);
- SVN_ERR (svn_io_file_write_full (destfile, buf, bytes_used, NULL,
pool));- SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, pool));
+ buf = apr_psprintf (iterpool, "%" APR_SIZE_T_FMT, value->len);
+ SVN_ERR (svn_io_file_write_full (destfile, buf,
+ strlen (buf), NULL, iterpool));
+ SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, iterpool));
  
       SVN_ERR (svn_io_file_write_full (destfile, value->data, value->len,
- NULL, pool));
- SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, pool));
+ NULL, iterpool));
+ SVN_ERR (svn_io_file_write_full (destfile, "\n", 1, NULL, iterpool));
     }
  
+ svn_pool_destroy (iterpool);
+
   SVN_ERR (svn_io_file_write_full (destfile, "END\n", 4, NULL, pool));
  
   return SVN_NO_ERROR;

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Dec 2 21:13:16 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.