Skip to content

Commit

Permalink
AK: Make Nonnull*PtrVector use size_t for indexes
Browse files Browse the repository at this point in the history
This was weird. It turns out these class were using int indexes and
sizes despite being derived from Vector which uses size_t.

Make the universe right again by using size_t here as well.
  • Loading branch information
awesomekling committed Feb 20, 2021
1 parent 46efd2f commit 81c6d8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions AK/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class NonnullRefPtr;
template<typename T>
class NonnullOwnPtr;

template<typename T, int inline_capacity = 0>
template<typename T, size_t inline_capacity = 0>
class NonnullRefPtrVector;

template<typename T, int inline_capacity = 0>
template<typename T, size_t inline_capacity = 0>
class NonnullOwnPtrVector;

template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion AK/NonnullOwnPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace AK {

template<typename T, int inline_capacity>
template<typename T, size_t inline_capacity>
class NonnullOwnPtrVector : public NonnullPtrVector<NonnullOwnPtr<T>, inline_capacity> {
};

Expand Down
18 changes: 9 additions & 9 deletions AK/NonnullPtrVector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <[email protected]>
* Copyright (c) 2018-2021, Andreas Kling <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,7 +30,7 @@

namespace AK {

template<typename PtrType, int inline_capacity = 0>
template<typename PtrType, size_t inline_capacity = 0>
class NonnullPtrVector : public Vector<PtrType, inline_capacity> {
using T = typename PtrType::ElementType;
using Base = Vector<PtrType, inline_capacity>;
Expand Down Expand Up @@ -60,13 +60,13 @@ class NonnullPtrVector : public Vector<PtrType, inline_capacity> {
ALWAYS_INLINE constexpr ConstIterator end() const { return ConstIterator::end(*this); }
ALWAYS_INLINE constexpr Iterator end() { return Iterator::end(*this); }

ALWAYS_INLINE PtrType& ptr_at(int index) { return Base::at(index); }
ALWAYS_INLINE const PtrType& ptr_at(int index) const { return Base::at(index); }
ALWAYS_INLINE PtrType& ptr_at(size_t index) { return Base::at(index); }
ALWAYS_INLINE const PtrType& ptr_at(size_t index) const { return Base::at(index); }

ALWAYS_INLINE T& at(int index) { return *Base::at(index); }
ALWAYS_INLINE const T& at(int index) const { return *Base::at(index); }
ALWAYS_INLINE T& operator[](int index) { return at(index); }
ALWAYS_INLINE const T& operator[](int index) const { return at(index); }
ALWAYS_INLINE T& at(size_t index) { return *Base::at(index); }
ALWAYS_INLINE const T& at(size_t index) const { return *Base::at(index); }
ALWAYS_INLINE T& operator[](size_t index) { return at(index); }
ALWAYS_INLINE const T& operator[](size_t index) const { return at(index); }
ALWAYS_INLINE T& first() { return at(0); }
ALWAYS_INLINE const T& first() const { return at(0); }
ALWAYS_INLINE T& last() { return at(size() - 1); }
Expand All @@ -76,7 +76,7 @@ class NonnullPtrVector : public Vector<PtrType, inline_capacity> {
// NOTE: You can't use resize() on a NonnullFooPtrVector since making the vector
// bigger would require being able to default-construct NonnullFooPtrs.
// Instead, use shrink(new_size).
void resize(int) = delete;
void resize(size_t) = delete;
};

}
2 changes: 1 addition & 1 deletion AK/NonnullRefPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace AK {

template<typename T, int inline_capacity>
template<typename T, size_t inline_capacity>
class NonnullRefPtrVector : public NonnullPtrVector<NonnullRefPtr<T>, inline_capacity> {
};

Expand Down

0 comments on commit 81c6d8e

Please sign in to comment.