From 57cfdfd9796531a576060e9304715920e0fdb8fe Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 19 Apr 2012 11:59:54 +0100 Subject: [PATCH] Split cairo-list into struct+inlines References: https://bugs.freedesktop.org/show_bug.cgi?id=48577 Signed-off-by: Chris Wilson --- src/Makefile.sources | 1 + src/cairo-botor-scan-converter.c | 2 +- src/cairo-gstate.c | 1 + src/cairo-list-inline.h | 209 +++++++++++++++++++++++++++++ src/cairo-list-private.h | 167 ----------------------- src/cairo-observer.c | 2 + src/cairo-path-fixed.c | 1 + src/cairo-pattern-inline.h | 2 + src/cairo-pattern.c | 1 + src/cairo-ps-surface.c | 1 + src/cairo-rtree-private.h | 2 +- src/cairo-scaled-font.c | 1 + src/cairo-script-surface.c | 2 +- src/cairo-surface-observer.c | 1 + src/cairo-surface.c | 1 + src/cairo-xcb-connection.c | 2 +- src/cairo-xcb-screen.c | 1 + src/cairo-xcb-shm.c | 1 + src/cairo-xcb-surface-render.c | 1 + src/cairo-xcb-surface.c | 1 + src/cairo-xlib-display.c | 1 + src/cairo-xlib-render-compositor.c | 1 + src/cairo-xlib-screen.c | 1 + src/cairo-xlib-surface.c | 1 + src/cairo-xlib-xcb-surface.c | 1 + 25 files changed, 234 insertions(+), 171 deletions(-) create mode 100644 src/cairo-list-inline.h diff --git a/src/Makefile.sources b/src/Makefile.sources index 9ea87f86f..f487fc113 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -84,6 +84,7 @@ cairo_private = \ cairo-image-info-private.h \ cairo-image-surface-inline.h \ cairo-image-surface-private.h \ + cairo-list-inline.h \ cairo-list-private.h \ cairo-malloc-private.h \ cairo-mutex-impl-private.h \ diff --git a/src/cairo-botor-scan-converter.c b/src/cairo-botor-scan-converter.c index dc1ae6b1c..2729463b5 100644 --- a/src/cairo-botor-scan-converter.c +++ b/src/cairo-botor-scan-converter.c @@ -43,7 +43,7 @@ #include "cairoint.h" #include "cairo-error-private.h" -#include "cairo-list-private.h" +#include "cairo-list-inline.h" #include "cairo-freelist-private.h" #include "cairo-combsort-inline.h" diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index 889bc1aec..23e8b189f 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -40,6 +40,7 @@ #include "cairo-clip-inline.h" #include "cairo-clip-private.h" #include "cairo-error-private.h" +#include "cairo-list-inline.h" #include "cairo-gstate-private.h" #include "cairo-pattern-private.h" #include "cairo-traps-private.h" diff --git a/src/cairo-list-inline.h b/src/cairo-list-inline.h new file mode 100644 index 000000000..d00f40e98 --- /dev/null +++ b/src/cairo-list-inline.h @@ -0,0 +1,209 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + * + */ + +#ifndef CAIRO_LIST_INLINE_H +#define CAIRO_LIST_INLINE_H + +#include "cairo-list-private.h" + +#define cairo_list_entry(ptr, type, member) \ + cairo_container_of(ptr, type, member) + +#define cairo_list_first_entry(ptr, type, member) \ + cairo_list_entry((ptr)->next, type, member) + +#define cairo_list_last_entry(ptr, type, member) \ + cairo_list_entry((ptr)->prev, type, member) + +#define cairo_list_foreach(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +#define cairo_list_foreach_entry(pos, type, head, member) \ + for (pos = cairo_list_entry((head)->next, type, member);\ + &pos->member != (head); \ + pos = cairo_list_entry(pos->member.next, type, member)) + +#define cairo_list_foreach_entry_safe(pos, n, type, head, member) \ + for (pos = cairo_list_entry ((head)->next, type, member),\ + n = cairo_list_entry (pos->member.next, type, member);\ + &pos->member != (head); \ + pos = n, n = cairo_list_entry (n->member.next, type, member)) + +#define cairo_list_foreach_entry_reverse(pos, type, head, member) \ + for (pos = cairo_list_entry((head)->prev, type, member);\ + &pos->member != (head); \ + pos = cairo_list_entry(pos->member.prev, type, member)) + +#define cairo_list_foreach_entry_reverse_safe(pos, n, type, head, member) \ + for (pos = cairo_list_entry((head)->prev, type, member),\ + n = cairo_list_entry (pos->member.prev, type, member);\ + &pos->member != (head); \ + pos = n, n = cairo_list_entry (n->member.prev, type, member)) + +#ifdef CAIRO_LIST_DEBUG +static inline void +_cairo_list_validate (const cairo_list_t *link) +{ + assert (link->next->prev == link); + assert (link->prev->next == link); +} +static inline void +cairo_list_validate (const cairo_list_t *head) +{ + cairo_list_t *link; + + cairo_list_foreach (link, head) + _cairo_list_validate (link); +} +static inline cairo_bool_t +cairo_list_is_empty (const cairo_list_t *head); +static inline void +cairo_list_validate_is_empty (const cairo_list_t *head) +{ + assert (head->next == NULL || (cairo_list_is_empty (head) && head->next == head->prev)); +} +#else +#define _cairo_list_validate(link) +#define cairo_list_validate(head) +#define cairo_list_validate_is_empty(head) +#endif + +static inline void +cairo_list_init (cairo_list_t *entry) +{ + entry->next = entry; + entry->prev = entry; +} + +static inline void +__cairo_list_add (cairo_list_t *entry, + cairo_list_t *prev, + cairo_list_t *next) +{ + next->prev = entry; + entry->next = next; + entry->prev = prev; + prev->next = entry; +} + +static inline void +cairo_list_add (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + cairo_list_validate_is_empty (entry); + __cairo_list_add (entry, head, head->next); + cairo_list_validate (head); +} + +static inline void +cairo_list_add_tail (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + cairo_list_validate_is_empty (entry); + __cairo_list_add (entry, head->prev, head); + cairo_list_validate (head); +} + +static inline void +__cairo_list_del (cairo_list_t *prev, cairo_list_t *next) +{ + next->prev = prev; + prev->next = next; +} + +static inline void +cairo_list_del (cairo_list_t *entry) +{ + __cairo_list_del (entry->prev, entry->next); + cairo_list_init (entry); +} + +static inline void +cairo_list_move (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + __cairo_list_del (entry->prev, entry->next); + __cairo_list_add (entry, head, head->next); + cairo_list_validate (head); +} + +static inline void +cairo_list_move_tail (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + __cairo_list_del (entry->prev, entry->next); + __cairo_list_add (entry, head->prev, head); + cairo_list_validate (head); +} + +static inline void +cairo_list_swap (cairo_list_t *entry, cairo_list_t *other) +{ + __cairo_list_add (entry, other->prev, other->next); + cairo_list_init (other); +} + +static inline cairo_bool_t +cairo_list_is_first (const cairo_list_t *entry, + const cairo_list_t *head) +{ + cairo_list_validate (head); + return entry->prev == head; +} + +static inline cairo_bool_t +cairo_list_is_last (const cairo_list_t *entry, + const cairo_list_t *head) +{ + cairo_list_validate (head); + return entry->next == head; +} + +static inline cairo_bool_t +cairo_list_is_empty (const cairo_list_t *head) +{ + cairo_list_validate (head); + return head->next == head; +} + +static inline cairo_bool_t +cairo_list_is_singular (const cairo_list_t *head) +{ + cairo_list_validate (head); + return head->next == head || head->next == head->prev; +} + +#endif /* CAIRO_LIST_INLINE_H */ diff --git a/src/cairo-list-private.h b/src/cairo-list-private.h index ddfd0a4c6..9f39b668f 100644 --- a/src/cairo-list-private.h +++ b/src/cairo-list-private.h @@ -45,171 +45,4 @@ typedef struct _cairo_list { struct _cairo_list *next, *prev; } cairo_list_t; -#define cairo_list_entry(ptr, type, member) \ - cairo_container_of(ptr, type, member) - -#define cairo_list_first_entry(ptr, type, member) \ - cairo_list_entry((ptr)->next, type, member) - -#define cairo_list_last_entry(ptr, type, member) \ - cairo_list_entry((ptr)->prev, type, member) - -#define cairo_list_foreach(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) - -#define cairo_list_foreach_entry(pos, type, head, member) \ - for (pos = cairo_list_entry((head)->next, type, member);\ - &pos->member != (head); \ - pos = cairo_list_entry(pos->member.next, type, member)) - -#define cairo_list_foreach_entry_safe(pos, n, type, head, member) \ - for (pos = cairo_list_entry ((head)->next, type, member),\ - n = cairo_list_entry (pos->member.next, type, member);\ - &pos->member != (head); \ - pos = n, n = cairo_list_entry (n->member.next, type, member)) - -#define cairo_list_foreach_entry_reverse(pos, type, head, member) \ - for (pos = cairo_list_entry((head)->prev, type, member);\ - &pos->member != (head); \ - pos = cairo_list_entry(pos->member.prev, type, member)) - -#define cairo_list_foreach_entry_reverse_safe(pos, n, type, head, member) \ - for (pos = cairo_list_entry((head)->prev, type, member),\ - n = cairo_list_entry (pos->member.prev, type, member);\ - &pos->member != (head); \ - pos = n, n = cairo_list_entry (n->member.prev, type, member)) - -#ifdef CAIRO_LIST_DEBUG -static inline void -_cairo_list_validate (const cairo_list_t *link) -{ - assert (link->next->prev == link); - assert (link->prev->next == link); -} -static inline void -cairo_list_validate (const cairo_list_t *head) -{ - cairo_list_t *link; - - cairo_list_foreach (link, head) - _cairo_list_validate (link); -} -static inline cairo_bool_t -cairo_list_is_empty (const cairo_list_t *head); -static inline void -cairo_list_validate_is_empty (const cairo_list_t *head) -{ - assert (head->next == NULL || (cairo_list_is_empty (head) && head->next == head->prev)); -} -#else -#define _cairo_list_validate(link) -#define cairo_list_validate(head) -#define cairo_list_validate_is_empty(head) -#endif - -static inline void -cairo_list_init (cairo_list_t *entry) -{ - entry->next = entry; - entry->prev = entry; -} - -static inline void -__cairo_list_add (cairo_list_t *entry, - cairo_list_t *prev, - cairo_list_t *next) -{ - next->prev = entry; - entry->next = next; - entry->prev = prev; - prev->next = entry; -} - -static inline void -cairo_list_add (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - cairo_list_validate_is_empty (entry); - __cairo_list_add (entry, head, head->next); - cairo_list_validate (head); -} - -static inline void -cairo_list_add_tail (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - cairo_list_validate_is_empty (entry); - __cairo_list_add (entry, head->prev, head); - cairo_list_validate (head); -} - -static inline void -__cairo_list_del (cairo_list_t *prev, cairo_list_t *next) -{ - next->prev = prev; - prev->next = next; -} - -static inline void -cairo_list_del (cairo_list_t *entry) -{ - __cairo_list_del (entry->prev, entry->next); - cairo_list_init (entry); -} - -static inline void -cairo_list_move (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - __cairo_list_del (entry->prev, entry->next); - __cairo_list_add (entry, head, head->next); - cairo_list_validate (head); -} - -static inline void -cairo_list_move_tail (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - __cairo_list_del (entry->prev, entry->next); - __cairo_list_add (entry, head->prev, head); - cairo_list_validate (head); -} - -static inline void -cairo_list_swap (cairo_list_t *entry, cairo_list_t *other) -{ - __cairo_list_add (entry, other->prev, other->next); - cairo_list_init (other); -} - -static inline cairo_bool_t -cairo_list_is_first (const cairo_list_t *entry, - const cairo_list_t *head) -{ - cairo_list_validate (head); - return entry->prev == head; -} - -static inline cairo_bool_t -cairo_list_is_last (const cairo_list_t *entry, - const cairo_list_t *head) -{ - cairo_list_validate (head); - return entry->next == head; -} - -static inline cairo_bool_t -cairo_list_is_empty (const cairo_list_t *head) -{ - cairo_list_validate (head); - return head->next == head; -} - -static inline cairo_bool_t -cairo_list_is_singular (const cairo_list_t *head) -{ - cairo_list_validate (head); - return head->next == head || head->next == head->prev; -} - #endif /* CAIRO_LIST_PRIVATE_H */ diff --git a/src/cairo-observer.c b/src/cairo-observer.c index 7c7b69c91..36d6b93bd 100644 --- a/src/cairo-observer.c +++ b/src/cairo-observer.c @@ -36,6 +36,8 @@ #include "cairoint.h" +#include "cairo-list-inline.h" + void _cairo_observers_notify (cairo_list_t *observers, void *arg) { diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c index e86a489e5..459c680f3 100644 --- a/src/cairo-path-fixed.c +++ b/src/cairo-path-fixed.c @@ -40,6 +40,7 @@ #include "cairo-box-inline.h" #include "cairo-error-private.h" +#include "cairo-list-inline.h" #include "cairo-path-fixed-private.h" #include "cairo-slope-private.h" diff --git a/src/cairo-pattern-inline.h b/src/cairo-pattern-inline.h index 760c787f1..97e8ea034 100644 --- a/src/cairo-pattern-inline.h +++ b/src/cairo-pattern-inline.h @@ -38,6 +38,8 @@ #include "cairo-pattern-private.h" +#include "cairo-list-inline.h" + CAIRO_BEGIN_DECLS static inline void diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 3904c7515..d21200a52 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -34,6 +34,7 @@ #include "cairo-error-private.h" #include "cairo-freed-pool-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-path-private.h" #include "cairo-pattern-private.h" #include "cairo-recording-surface-inline.h" diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index dc01c6c32..f66740044 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -67,6 +67,7 @@ #include "cairo-default-context-private.h" #include "cairo-error-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-scaled-font-subsets-private.h" #include "cairo-paginated-private.h" #include "cairo-recording-surface-private.h" diff --git a/src/cairo-rtree-private.h b/src/cairo-rtree-private.h index b8db477af..27806cab6 100644 --- a/src/cairo-rtree-private.h +++ b/src/cairo-rtree-private.h @@ -42,7 +42,7 @@ #include "cairo-types-private.h" #include "cairo-freelist-private.h" -#include "cairo-list-private.h" +#include "cairo-list-inline.h" enum { CAIRO_RTREE_NODE_AVAILABLE, diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index e6552ec67..59440b2c3 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -41,6 +41,7 @@ #include "cairoint.h" #include "cairo-error-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-pattern-private.h" #include "cairo-scaled-font-private.h" #include "cairo-surface-backend-private.h" diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c index 879281d3e..e6867c1c7 100644 --- a/src/cairo-script-surface.c +++ b/src/cairo-script-surface.c @@ -73,7 +73,7 @@ #include "cairo-default-context-private.h" #include "cairo-device-private.h" #include "cairo-error-private.h" -#include "cairo-list-private.h" +#include "cairo-list-inline.h" #include "cairo-image-surface-private.h" #include "cairo-output-stream-private.h" #include "cairo-pattern-private.h" diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c index 49291411f..9247bc4da 100644 --- a/src/cairo-surface-observer.c +++ b/src/cairo-surface-observer.c @@ -43,6 +43,7 @@ #include "cairo-composite-rectangles-private.h" #include "cairo-error-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-pattern-private.h" #include "cairo-output-stream-private.h" #include "cairo-recording-surface-private.h" diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 7524db930..457b3f00a 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -44,6 +44,7 @@ #include "cairo-damage-private.h" #include "cairo-device-private.h" #include "cairo-error-private.h" +#include "cairo-list-inline.h" #include "cairo-image-surface-inline.h" #include "cairo-recording-surface-private.h" #include "cairo-region-private.h" diff --git a/src/cairo-xcb-connection.c b/src/cairo-xcb-connection.c index cbe815494..b48add17b 100644 --- a/src/cairo-xcb-connection.c +++ b/src/cairo-xcb-connection.c @@ -35,7 +35,7 @@ #include "cairo-xcb-private.h" #include "cairo-hash-private.h" #include "cairo-freelist-private.h" -#include "cairo-list-private.h" +#include "cairo-list-inline.h" #include #include diff --git a/src/cairo-xcb-screen.c b/src/cairo-xcb-screen.c index 9dd476e29..2858d23fb 100644 --- a/src/cairo-xcb-screen.c +++ b/src/cairo-xcb-screen.c @@ -33,6 +33,7 @@ #include "cairoint.h" #include "cairo-xcb-private.h" +#include "cairo-list-inline.h" struct pattern_cache_entry { cairo_cache_entry_t key; diff --git a/src/cairo-xcb-shm.c b/src/cairo-xcb-shm.c index 52440360e..d655e628a 100644 --- a/src/cairo-xcb-shm.c +++ b/src/cairo-xcb-shm.c @@ -39,6 +39,7 @@ #if CAIRO_HAS_XCB_SHM_FUNCTIONS #include "cairo-xcb-private.h" +#include "cairo-list-inline.h" #include #include diff --git a/src/cairo-xcb-surface-render.c b/src/cairo-xcb-surface-render.c index d41363e26..7736ed81b 100644 --- a/src/cairo-xcb-surface-render.c +++ b/src/cairo-xcb-surface-render.c @@ -38,6 +38,7 @@ #include "cairo-clip-private.h" #include "cairo-composite-rectangles-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-region-private.h" #include "cairo-surface-offset-private.h" #include "cairo-surface-snapshot-inline.h" diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c index 6bedbda00..4b1b906df 100644 --- a/src/cairo-xcb-surface.c +++ b/src/cairo-xcb-surface.c @@ -45,6 +45,7 @@ #include "cairo-composite-rectangles-private.h" #include "cairo-default-context-private.h" +#include "cairo-list-inline.h" #include "cairo-image-surface-private.h" #include "cairo-surface-backend-private.h" diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c index 74c085e31..e685c7cd8 100644 --- a/src/cairo-xlib-display.c +++ b/src/cairo-xlib-display.c @@ -41,6 +41,7 @@ #include "cairo-xlib-xrender-private.h" #include "cairo-freelist-private.h" #include "cairo-error-private.h" +#include "cairo-list-inline.h" #include /* For XESetCloseDisplay */ diff --git a/src/cairo-xlib-render-compositor.c b/src/cairo-xlib-render-compositor.c index 401313bd5..a892985b7 100644 --- a/src/cairo-xlib-render-compositor.c +++ b/src/cairo-xlib-render-compositor.c @@ -48,6 +48,7 @@ #include "cairo-compositor-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-pattern-private.h" #include "cairo-traps-private.h" #include "cairo-tristrip-private.h" diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c index 7bfdf1581..57beeaab4 100644 --- a/src/cairo-xlib-screen.c +++ b/src/cairo-xlib-screen.c @@ -61,6 +61,7 @@ #include "cairo-xlib-surface-private.h" #include "cairo-error-private.h" +#include "cairo-list-inline.h" #include "cairo-fontconfig-private.h" diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 489e52d20..0645da684 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -57,6 +57,7 @@ #include "cairo-default-context-private.h" #include "cairo-error-private.h" #include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" #include "cairo-pattern-private.h" #include "cairo-region-private.h" #include "cairo-scaled-font-private.h" diff --git a/src/cairo-xlib-xcb-surface.c b/src/cairo-xlib-xcb-surface.c index 2f8fb4c5c..caa9bd31e 100644 --- a/src/cairo-xlib-xcb-surface.c +++ b/src/cairo-xlib-xcb-surface.c @@ -47,6 +47,7 @@ #include "cairo-xlib-xrender-private.h" #include "cairo-default-context-private.h" +#include "cairo-list-inline.h" #include "cairo-image-surface-private.h" #include "cairo-surface-backend-private.h"