[Freeciv-Dev] (PR#8786) Small specvec changes
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8786 >
Reason for:
if (index == -1 && tthis->size > 0) {
return tthis->p + tthis->size - 1;
} else if (index >= 0 && index < tthis->size) {
return tthis->p + index;
} else {
return NULL;
}
less redundant, more compact and with a clean else case.
Reason for the other change:
I think the variable is misnamed here. Because of the reserve call the
meaning changes from "size" to "index of last element".
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Heuer's Law: Any feature is a bug unless it can be turned off."
Index: utility/specvec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/specvec.h,v
retrieving revision 1.6
diff -u -u -r1.6 specvec.h
--- utility/specvec.h 19 May 2004 20:07:33 -0000 1.6
+++ utility/specvec.h 20 May 2004 17:27:17 -0000
@@ -103,21 +103,15 @@
return tthis->size;
}
-static inline SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (SPECVEC_VECTOR *tthis,
+static inline SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (SPECVEC_VECTOR * tthis,
int index)
{
- if (index == -1) {
- if (tthis->size > 0) {
- return tthis->p + tthis->size - 1;
- } else {
- return NULL;
- }
+ if (index == -1 && tthis->size > 0) {
+ return tthis->p + tthis->size - 1;
+ } else if (index >= 0 && index < tthis->size) {
+ return tthis->p + index;
} else {
- if (index < 0 || index >= tthis->size) {
- return NULL;
- } else {
- return tthis->p + index;
- }
+ return NULL;
}
}
@@ -137,17 +131,13 @@
SPECVEC_FOO(_vector_init)(tthis);
}
-static inline void SPECVEC_FOO(_vector_append) (SPECVEC_VECTOR *tthis,
- SPECVEC_TYPE *pfoo)
+static inline void SPECVEC_FOO(_vector_append) (SPECVEC_VECTOR * tthis,
+ SPECVEC_TYPE * pfoo)
{
- const size_t last = tthis->size;
-
- SPECVEC_FOO(_vector_reserve) (tthis, last + 1);
- tthis->p[last] = *pfoo;
+ SPECVEC_FOO(_vector_reserve) (tthis, tthis->size + 1);
+ tthis->p[tthis->size - 1] = *pfoo;
}
-
-
#define TYPED_VECTOR_ITERATE(atype, vector, var) { \
int myiter; \
atype *var; \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8786) Small specvec changes,
Raimar Falke <=
|
|