mirror of https://github.com/xzeldon/htop.git
Avoid calling Object_isA from inside Vector_isConsistent
This commit is contained in:
parent
307c34b028
commit
a94fd87b05
5
Object.c
5
Object.c
|
@ -21,13 +21,10 @@ bool Object_isA(const Object* o, const ObjectClass* klass) {
|
||||||
if (!o)
|
if (!o)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ObjectClass* type = o->klass;
|
for (const ObjectClass* type = o->klass; type; type = type->extends) {
|
||||||
while (type) {
|
|
||||||
if (type == klass) {
|
if (type == klass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
type = type->extends;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
12
Vector.c
12
Vector.c
|
@ -48,16 +48,16 @@ void Vector_delete(Vector* this) {
|
||||||
|
|
||||||
static bool Vector_isConsistent(const Vector* this) {
|
static bool Vector_isConsistent(const Vector* this) {
|
||||||
assert(this->items <= this->arraySize);
|
assert(this->items <= this->arraySize);
|
||||||
|
|
||||||
if (this->owner) {
|
if (this->owner) {
|
||||||
for (int i = 0; i < this->items; i++) {
|
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 false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Vector_count(const Vector* this) {
|
unsigned int Vector_count(const Vector* this) {
|
||||||
|
@ -71,10 +71,10 @@ unsigned int Vector_count(const Vector* this) {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* Vector_get(Vector* this, int idx) {
|
Object* Vector_get(const Vector* this, int idx) {
|
||||||
assert(idx >= 0 && idx < this->items);
|
assert(idx >= 0 && idx < this->items);
|
||||||
assert(Vector_isConsistent(this));
|
|
||||||
assert(this->array[idx]);
|
assert(this->array[idx]);
|
||||||
|
assert(Object_isA(this->array[idx], this->type));
|
||||||
return this->array[idx];
|
return this->array[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
Vector.h
2
Vector.h
|
@ -52,7 +52,7 @@ void Vector_set(Vector* this, int idx, void* data_);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
Object* Vector_get(Vector* this, int idx);
|
Object* Vector_get(const Vector* this, int idx);
|
||||||
int Vector_size(const Vector* this);
|
int Vector_size(const Vector* this);
|
||||||
unsigned int Vector_count(const Vector* this);
|
unsigned int Vector_count(const Vector* this);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue