X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c5b15840ab1bb70218506531f9a73fe2d112b007..1e8d80477a3e058a30c477955f1e0c56deb6e956:/List.hpp?ds=sidebyside diff --git a/List.hpp b/List.hpp index 4caa536..d2acedf 100644 --- a/List.hpp +++ b/List.hpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -22,6 +22,8 @@ #ifndef CYCRIPT_LIST_HPP #define CYCRIPT_LIST_HPP +#include "Exception.hpp" + template struct CYNext { Type_ *next_; @@ -68,12 +70,24 @@ struct CYList { Type_ *first_; Type_ *last_; - CYList(Type_ *first = NULL) : + CYList() : + first_(NULL), + last_(NULL) + { + } + + CYList(Type_ *first) : first_(first), last_(CYGetLast(first)) { } + CYList(Type_ *first, Type_ *last) : + first_(first), + last_(last) + { + } + operator Type_ *() const { return first_; } @@ -87,12 +101,11 @@ struct CYList { if (first_ == NULL) { first_ = next; last_ = next; - } else for (;; last_ = last_->next_) - if (last_->next_ == NULL) { - last_->next_ = next; - last_ = next; - break; - } + } else { + _assert(last_->next_ == NULL); + last_->next_ = next; + last_ = next; + } return *this; }