diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-02-13 12:56:46 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-02-13 13:08:24 +0000 |
commit | adaf70a93f4449e85997bcde531b76c9044758ea (patch) | |
tree | 837fb1636b2f7b1ca8a4abf013c383b94f2c1070 /src/cairo-array.c | |
parent | 2280de9d0282a599309ec12dc576bae54857f873 (diff) |
[surface] Separate the mime-data from the user-data.
Move the mime-data into its own array so that it cannot be confused with
user-data and we do not need to hard-code the copy list during
snapshotting. The copy-on-snapshotting code becomes far simpler and will
accommodate all future mime-types.
Keeping mime-data separate from user-data is important due to the
principle of least surprise - the API is different and so it would be
surprising if you queried for user-data and were returned an opaque
mime-data pointer, and vice versa. (Note this should have been prevented
by using interned strings, but conceptually it is cleaner to make the
separation.) Also it aides in trimming the user data arrays which are
linearly searched.
Based on the original patch by Adrian Johnson:
http://cgit.freedesktop.org/~ajohnson/cairo/commit/?h=metadata&id=37e607cc777523ad12a2d214708d79ecbca5b380
Diffstat (limited to 'src/cairo-array.c')
-rw-r--r-- | src/cairo-array.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cairo-array.c b/src/cairo-array.c index 9c084b9e..70c16465 100644 --- a/src/cairo-array.c +++ b/src/cairo-array.c @@ -494,3 +494,39 @@ _cairo_user_data_array_set_data (cairo_user_data_array_t *array, return CAIRO_STATUS_SUCCESS; } + +cairo_status_t +_cairo_user_data_array_copy (cairo_user_data_array_t *dst, + cairo_user_data_array_t *src) +{ + /* discard any existing user-data */ + if (dst->num_elements != 0) { + _cairo_user_data_array_fini (dst); + _cairo_user_data_array_init (dst); + } + + if (src->num_elements == 0) + return CAIRO_STATUS_SUCCESS; + + return _cairo_array_append_multiple (dst, + _cairo_array_index (src, 0), + src->num_elements); +} + +void +_cairo_user_data_array_foreach (cairo_user_data_array_t *array, + void (*func) (void *key, + void *elt, + void *closure), + void *closure) +{ + cairo_user_data_slot_t *slots; + int i, num_slots; + + num_slots = array->num_elements; + slots = _cairo_array_index (array, 0); + for (i = 0; i < num_slots; i++) { + if (slots[i].user_data != NULL) + func (slots[i].key, slots[i].user_data, closure); + } +} |