summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-02-27 04:17:44 +0000
committerHavoc Pennington <hp@redhat.com>2003-02-27 04:17:44 +0000
commit13f70ce711630d7f70c0b11fa57639fad95e4afd (patch)
tree80cbda896b78ff763f0c989576ac84e604ace026 /dbus/dbus-string.c
parentb7bc5ba7a323c6a17a442310c40585b67edff5d4 (diff)
2003-02-27 Havoc Pennington <hp@pobox.com>
* dbus/dbus-marshal.c (_dbus_demarshal_int32): rewrite to be much more inlined, using dbus-string-private.h, speeds things up substantially * dbus/dbus-string.c (_dbus_string_free): apply align offset when freeing the string (_dbus_string_steal_data): fix for align offset (undo_alignment): new function
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 22d000da..f19a30db 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -25,6 +25,9 @@
#include "dbus-string.h"
/* we allow a system header here, for speed/convenience */
#include <string.h>
+#include "dbus-marshal.h"
+#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
+#include "dbus-string-private.h"
/**
* @defgroup DBusString string class
@@ -64,24 +67,6 @@
*/
/**
- * @brief Internals of DBusString.
- *
- * DBusString internals. DBusString is an opaque objects, it must be
- * used via accessor functions.
- */
-typedef struct
-{
- unsigned char *str; /**< String data, plus nul termination */
- int len; /**< Length without nul */
- int allocated; /**< Allocated size of data */
- int max_length; /**< Max length of this string, without nul byte */
- unsigned int constant : 1; /**< String data is not owned by DBusString */
- unsigned int locked : 1; /**< DBusString has been locked and can't be changed */
- unsigned int invalid : 1; /**< DBusString is invalid (e.g. already freed) */
- unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */
-} DBusRealString;
-
-/**
* We allocate 1 byte for nul termination, plus 7 bytes for possible
* align_offset, so we always need 8 bytes on top of the string's
* length to be in the allocated block.
@@ -168,6 +153,20 @@ fixup_alignment (DBusRealString *real)
_dbus_assert (_DBUS_ALIGN_ADDRESS (real->str, 8) == real->str);
}
+static void
+undo_alignment (DBusRealString *real)
+{
+ if (real->align_offset != 0)
+ {
+ memmove (real->str - real->align_offset,
+ real->str,
+ real->len + 1);
+
+ real->align_offset = 0;
+ real->str = real->str - real->align_offset;
+ }
+}
+
/**
* Initializes a string. The maximum length may be _DBUS_INT_MAX for
* no maximum. The string starts life with zero length.
@@ -296,7 +295,7 @@ _dbus_string_free (DBusString *str)
if (real->constant)
return;
- dbus_free (real->str);
+ dbus_free (real->str - real->align_offset);
real->invalid = TRUE;
}
@@ -577,6 +576,8 @@ _dbus_string_steal_data (DBusString *str,
{
DBUS_STRING_PREAMBLE (str);
_dbus_assert (data_return != NULL);
+
+ undo_alignment (real);
*data_return = real->str;
@@ -586,6 +587,7 @@ _dbus_string_steal_data (DBusString *str,
/* hrm, put it back then */
real->str = *data_return;
*data_return = NULL;
+ fixup_alignment (real);
return FALSE;
}
@@ -2447,7 +2449,6 @@ _dbus_string_zero (DBusString *str)
memset (real->str, '\0', real->allocated);
}
-
/** @} */
#ifdef DBUS_BUILD_TESTS