summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-marshal-recursive.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-01-16 02:23:56 +0000
committerHavoc Pennington <hp@redhat.com>2005-01-16 02:23:56 +0000
commitb3416423b1e3c17357833d896c1b7cd684660771 (patch)
tree9f8ae4a2d65337f6b668aca787eadb8342e05db2 /dbus/dbus-marshal-recursive.c
parent9c3d566e95c9080f6040c64531b0ccae22bd5d74 (diff)
2005-01-15 Havoc Pennington <hp@redhat.com>
* test/glib/test-profile.c (with_bus_server_filter): fix crash * dbus/dbus-marshal-basic.c (_dbus_unpack_uint32): inline as macro when DBUS_DISABLE_ASSERT (_dbus_marshal_set_basic): be sure we align for the string length * dbus/dbus-marshal-recursive.c (skip_one_complete_type): make this look faster * dbus/dbus-string.c (_dbus_string_get_const_data_len): add an inline macro version (_dbus_string_set_byte): provide inline macro version
Diffstat (limited to 'dbus/dbus-marshal-recursive.c')
-rw-r--r--dbus/dbus-marshal-recursive.c83
1 files changed, 52 insertions, 31 deletions
diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c
index 3b2ce91d..a8bad46a 100644
--- a/dbus/dbus-marshal-recursive.c
+++ b/dbus/dbus-marshal-recursive.c
@@ -119,7 +119,7 @@ static int
first_type_in_signature (const DBusString *str,
int pos)
{
- int t;
+ unsigned char t;
t = _dbus_string_get_byte (str, pos);
@@ -213,13 +213,10 @@ array_reader_get_array_len (const DBusTypeReader *reader)
len_pos = ARRAY_READER_LEN_POS (reader);
- _dbus_marshal_read_basic (reader->value_str,
- len_pos,
- DBUS_TYPE_UINT32,
- &array_len,
- reader->byte_order,
- NULL);
-
+ _dbus_assert (_DBUS_ALIGN_VALUE (len_pos, 4) == (unsigned) len_pos);
+ array_len = _dbus_unpack_uint32 (reader->byte_order,
+ _dbus_string_get_const_data_len (reader->value_str, len_pos, 4));
+
#if RECURSIVE_MARSHAL_READ_TRACE
_dbus_verbose (" reader %p len_pos %d array len %u len_offset %d\n",
reader, len_pos, array_len, reader->array_len_offset);
@@ -311,37 +308,55 @@ array_reader_check_finished (const DBusTypeReader *reader)
return reader->value_pos == end_pos;
}
+/* this is written a little oddly to try and overoptimize */
static void
skip_one_complete_type (const DBusString *type_str,
int *type_pos)
{
- while (_dbus_string_get_byte (type_str, *type_pos) == DBUS_TYPE_ARRAY)
- *type_pos += 1;
+ const unsigned char *p;
+ const unsigned char *start;
+
+ start = _dbus_string_get_const_data (type_str);
+ p = start + *type_pos;
- if (_dbus_string_get_byte (type_str, *type_pos) == DBUS_STRUCT_BEGIN_CHAR)
+ while (*p == DBUS_TYPE_ARRAY)
+ ++p;
+
+ if (*p == DBUS_STRUCT_BEGIN_CHAR)
{
int depth;
+
depth = 1;
- *type_pos += 1;
- while (depth > 0)
+
+ while (TRUE)
{
- switch (_dbus_string_get_byte (type_str, *type_pos))
+ _dbus_assert (*p != DBUS_TYPE_INVALID);
+
+ ++p;
+
+ _dbus_assert (*p != DBUS_TYPE_INVALID);
+
+ if (*p == DBUS_STRUCT_BEGIN_CHAR)
+ depth += 1;
+ else if (*p == DBUS_STRUCT_END_CHAR)
{
- case DBUS_STRUCT_BEGIN_CHAR:
- depth += 1;
- break;
- case DBUS_STRUCT_END_CHAR:
depth -= 1;
- break;
- case DBUS_TYPE_INVALID:
- _dbus_assert_not_reached ("unbalanced parens in signature");
- break;
+ if (depth == 0)
+ {
+ ++p;
+ break;
+ }
}
- *type_pos += 1;
}
}
else
- *type_pos += 1;
+ {
+ ++p;
+ }
+
+ _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+
+ *type_pos = (int) (p - start);
}
static int
@@ -1831,10 +1846,13 @@ writer_recurse_array (DBusTypeWriter *writer,
{
dbus_uint32_t len;
- len = _dbus_marshal_read_uint32 (sub->value_str,
- sub->u.array.len_pos,
- sub->byte_order, NULL);
-
+ _dbus_assert (_DBUS_ALIGN_VALUE (sub->u.array.len_pos, 4) ==
+ (unsigned) sub->u.array.len_pos);
+ len = _dbus_unpack_uint32 (sub->byte_order,
+ _dbus_string_get_const_data_len (sub->value_str,
+ sub->u.array.len_pos,
+ 4));
+
sub->value_pos += len;
}
}
@@ -2432,9 +2450,12 @@ writer_write_reader_helper (DBusTypeWriter *writer,
start_after_new_len +
bytes_written_after_start_after;
- old_len = _dbus_marshal_read_uint32 (reader->value_str,
- fixup.len_pos_in_reader,
- reader->byte_order, NULL);
+ _dbus_assert (_DBUS_ALIGN_VALUE (fixup.len_pos_in_reader, 4) ==
+ (unsigned) fixup.len_pos_in_reader);
+
+ old_len = _dbus_unpack_uint32 (reader->byte_order,
+ _dbus_string_get_const_data_len (reader->value_str,
+ fixup.len_pos_in_reader, 4));
if (old_len != fixup.new_len && !append_fixup (fixups, &fixup))
goto oom;