aboutsummaryrefslogtreecommitdiff
path: root/src/rt/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/rt/util')
-rw-r--r--src/rt/util/array_list.h17
-rw-r--r--src/rt/util/indexed_list.h9
2 files changed, 20 insertions, 6 deletions
diff --git a/src/rt/util/array_list.h b/src/rt/util/array_list.h
index 929117f3..d44111e8 100644
--- a/src/rt/util/array_list.h
+++ b/src/rt/util/array_list.h
@@ -15,7 +15,7 @@ public:
size_t size();
int32_t append(T value);
int32_t push(T value);
- T pop();
+ bool pop(T *value);
bool replace(T old_value, T new_value);
int32_t index_of(T value);
bool is_empty();
@@ -54,10 +54,17 @@ array_list<T>::push(T value) {
return _size - 1;
}
-template<typename T> T
-array_list<T>::pop() {
- T value = _data[-- _size];
- return value;
+template<typename T> bool
+array_list<T>::pop(T *value) {
+ if (_size == 0) {
+ return false;
+ }
+ if (value != NULL) {
+ *value = _data[-- _size];
+ } else {
+ -- _size;
+ }
+ return true;
}
/**
diff --git a/src/rt/util/indexed_list.h b/src/rt/util/indexed_list.h
index d869d43e..cd39a0b6 100644
--- a/src/rt/util/indexed_list.h
+++ b/src/rt/util/indexed_list.h
@@ -24,6 +24,7 @@ template<typename T> class indexed_list {
public:
indexed_list(memory_region &region) : region(region) {}
virtual int32_t append(T *value);
+ virtual bool pop(T **value);
virtual size_t length() {
return list.size();
}
@@ -48,7 +49,8 @@ indexed_list<T>::remove(T *value) {
assert (value->list_index >= 0);
assert (value->list_index < (int32_t)list.size());
int32_t removeIndex = value->list_index;
- T *last = list.pop();
+ T *last;
+ list.pop(&last);
if (last->list_index == removeIndex) {
last->list_index = -1;
return removeIndex;
@@ -60,6 +62,11 @@ indexed_list<T>::remove(T *value) {
}
}
+template<typename T> bool
+indexed_list<T>::pop(T **value) {
+ return list.pop(value);
+}
+
template <typename T> T *
indexed_list<T>::operator[](int32_t index) {
T *value = list[index];