summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-05-07 17:53:58 +0200
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-05-07 17:53:58 +0200
commit837822b5c6924be7fbc297bcef9639d7ada95a30 (patch)
treefe8e3096dbefb700f691a3ce42ad1f9ee8474650 /src
parentc3744b6736ce45c1c700b7f026fb0acfb0069a6d (diff)
downloadxine-lib-837822b5c6924be7fbc297bcef9639d7ada95a30.tar.gz
xine-lib-837822b5c6924be7fbc297bcef9639d7ada95a30.tar.bz2
Simplify MRL_FREE and MRL_DUPLICATE macros.
There is no need to check if a pointer is not NULL before freeing it, so just call free() during MRL_FREE. During duplication, always prefer freeing and recreating to reallocating, as that would probably take more time than would actually be needed to allocate a new memory area. Also, most likely the duplication will happen on a new instance.
Diffstat (limited to 'src')
-rw-r--r--src/input/input_plugin.h83
1 files changed, 28 insertions, 55 deletions
diff --git a/src/input/input_plugin.h b/src/input/input_plugin.h
index 1d1e5cf53..4790164d5 100644
--- a/src/input/input_plugin.h
+++ b/src/input/input_plugin.h
@@ -333,65 +333,38 @@ struct input_plugin_s {
/*
* Freeing/zeroing all of entries of given mrl.
*/
-#define MRL_ZERO(m) { \
- if((m)) { \
- if((m)->origin) \
- free((m)->origin); \
- if((m)->mrl) \
- free((m)->mrl); \
- if((m)->link) \
- free((m)->link); \
- (m)->origin = NULL; \
- (m)->mrl = NULL; \
- (m)->link = NULL; \
- (m)->type = 0; \
- (m)->size = (off_t) 0; \
- } \
-}
+#define MRL_ZERO(m) { \
+ if((m)) { \
+ free((m)->origin); \
+ free((m)->mrl); \
+ free((m)->link); \
+ (m)->origin = NULL; \
+ (m)->mrl = NULL; \
+ (m)->link = NULL; \
+ (m)->type = 0; \
+ (m)->size = (off_t) 0; \
+ } \
+ }
/*
* Duplicate two mrls entries (s = source, d = destination).
*/
-#define MRL_DUPLICATE(s, d) { \
- _x_assert((s) != NULL); \
- _x_assert((d) != NULL); \
- \
- if((s)->origin) { \
- if((d)->origin) { \
- (d)->origin = (char *) realloc((d)->origin, strlen((s)->origin) + 1); \
- sprintf((d)->origin, "%s", (s)->origin); \
- } \
- else \
- (d)->origin = strdup((s)->origin); \
- } \
- else \
- (d)->origin = NULL; \
- \
- if((s)->mrl) { \
- if((d)->mrl) { \
- (d)->mrl = (char *) realloc((d)->mrl, strlen((s)->mrl) + 1); \
- sprintf((d)->mrl, "%s", (s)->mrl); \
- } \
- else \
- (d)->mrl = strdup((s)->mrl); \
- } \
- else \
- (d)->mrl = NULL; \
- \
- if((s)->link) { \
- if((d)->link) { \
- (d)->link = (char *) realloc((d)->link, strlen((s)->link) + 1); \
- sprintf((d)->link, "%s", (s)->link); \
- } \
- else \
- (d)->link = strdup((s)->link); \
- } \
- else \
- (d)->link = NULL; \
- \
- (d)->type = (s)->type; \
- (d)->size = (s)->size; \
-}
+#define MRL_DUPLICATE(s, d) { \
+ _x_assert((s) != NULL); \
+ _x_assert((d) != NULL); \
+ \
+ free((d)->origin); \
+ (d)->origin = (s)->origin ? strdup((s)->origin) : NULL; \
+ \
+ free((d)->mrl); \
+ (d)->mrl = (s)->mrl ? strdup((s)->mrl) : NULL; \
+ \
+ free((d)->link); \
+ (d)->link = (s)->link ? strdup((s)->link) : NULL; \
+ \
+ (d)->type = (s)->type; \
+ (d)->size = (s)->size; \
+ }
/*
* Duplicate two arrays of mrls (s = source, d = destination).