summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-11-17 01:27:27 +0100
committerBenBE <BenBE@geshi.org>2020-11-17 08:06:02 +0100
commita94fd87b05aa23d453d6e238746b5a55e75544bd (patch)
tree83c455f7aef55b120e6360bed623eaae76ce379f
parent307c34b028d353154aa268eceb38e0331c8275cf (diff)
Avoid calling Object_isA from inside Vector_isConsistent
-rw-r--r--Object.c5
-rw-r--r--Vector.c12
-rw-r--r--Vector.h2
3 files changed, 8 insertions, 11 deletions
diff --git a/Object.c b/Object.c
index 975c8d48..0a29d015 100644
--- a/Object.c
+++ b/Object.c
@@ -21,13 +21,10 @@ bool Object_isA(const Object* o, const ObjectClass* klass) {
if (!o)
return false;
- const ObjectClass* type = o->klass;
- while (type) {
+ for (const ObjectClass* type = o->klass; type; type = type->extends) {
if (type == klass) {
return true;
}
-
- type = type->extends;
}
return false;
diff --git a/Vector.c b/Vector.c
index 721ebdd3..40e6203f 100644
--- a/Vector.c
+++ b/Vector.c
@@ -48,16 +48,16 @@ void Vector_delete(Vector* this) {
static bool Vector_isConsistent(const Vector* this) {
assert(this->items <= this->arraySize);
+
if (this->owner) {
for (int i = 0; i < this->items; i++) {
- if (this->array[i] && !Object_isA(this->array[i], this->type)) {
+ if (!this->array[i]) {
return false;
}
}
- return true;
- } else {
- return true;
}
+
+ return true;
}
unsigned int Vector_count(const Vector* this) {
@@ -71,10 +71,10 @@ unsigned int Vector_count(const Vector* this) {
return items;
}
-Object* Vector_get(Vector* this, int idx) {
+Object* Vector_get(const Vector* this, int idx) {
assert(idx >= 0 && idx < this->items);
- assert(Vector_isConsistent(this));
assert(this->array[idx]);
+ assert(Object_isA(this->array[idx], this->type));
return this->array[idx];
}
diff --git a/Vector.h b/Vector.h
index ec354b16..ee514136 100644
--- a/Vector.h
+++ b/Vector.h
@@ -52,7 +52,7 @@ void Vector_set(Vector* this, int idx, void* data_);
#ifndef NDEBUG
-Object* Vector_get(Vector* this, int idx);
+Object* Vector_get(const Vector* this, int idx);
int Vector_size(const Vector* this);
unsigned int Vector_count(const Vector* this);

© 2014-2024 Faster IT GmbH | imprint | privacy policy