Changed array_list::replace() return behavior.
This commit is contained in:
parent
f043ee1d33
commit
76ba8f1d84
@ -53,7 +53,9 @@ rust_srv::realloc(void *p, size_t bytes)
|
||||
}
|
||||
void * val = ::realloc(p, bytes);
|
||||
#ifdef TRACK_ALLOCATIONS
|
||||
if (allocation_list.replace(p, val) == NULL) {
|
||||
if (allocation_list.replace(p, val) == false) {
|
||||
printf("realloc: ptr 0x%" PRIxPTR " is not in allocation_list\n",
|
||||
(uintptr_t) p);
|
||||
fatal("not in allocation_list", __FILE__, __LINE__);
|
||||
}
|
||||
#endif
|
||||
@ -64,8 +66,8 @@ void
|
||||
rust_srv::free(void *p)
|
||||
{
|
||||
#ifdef TRACK_ALLOCATIONS
|
||||
if (allocation_list.replace(p, NULL) == NULL) {
|
||||
printf("ptr 0x%" PRIxPTR " is not in allocation_list\n",
|
||||
if (allocation_list.replace(p, NULL) == false) {
|
||||
printf("free: ptr 0x%" PRIxPTR " is not in allocation_list\n",
|
||||
(uintptr_t) p);
|
||||
fatal("not in allocation_list", __FILE__, __LINE__);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
int32_t append(T value);
|
||||
int32_t push(T value);
|
||||
T pop();
|
||||
T replace(T old_value, T new_value);
|
||||
bool replace(T old_value, T new_value);
|
||||
int32_t index_of(T value);
|
||||
bool is_empty();
|
||||
T & operator[](size_t index);
|
||||
@ -62,16 +62,16 @@ array_list<T>::pop() {
|
||||
|
||||
/**
|
||||
* Replaces the old_value in the list with the new_value.
|
||||
* Returns the old_value if the replacement succeeded, or NULL otherwise.
|
||||
* Returns the true if the replacement succeeded, or false otherwise.
|
||||
*/
|
||||
template<typename T> T
|
||||
template<typename T> bool
|
||||
array_list<T>::replace(T old_value, T new_value) {
|
||||
int index = index_of(old_value);
|
||||
if (index < 0) {
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
_data[index] = new_value;
|
||||
return old_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T> int32_t
|
||||
|
Loading…
Reference in New Issue
Block a user