Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLat committed Jul 7, 2015
1 parent 0f1f76a commit 04e7d18
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ template <class T, int N=-1> class Pointer {
protected:
bool destroyed;
int index;
int length;
int len;
T* obj;
inline bool IsArray() {
return N != -1;
Expand Down Expand Up @@ -173,7 +173,7 @@ template <class T, int N=-1> class Pointer {
mmDestroy(Get());
}
else {
for (int i = 0; i < length; ++i) {
for (int i = 0; i < Length(); ++i) {
mmDestroy((*this)[i]);
}
}
Expand All @@ -183,12 +183,15 @@ template <class T, int N=-1> class Pointer {
void Clear(){
Set(-1);
}
void SetLength(int NewLength) {
len = NewLength;
}
public:
const int& Length() const{
return length;
return len;
}
const int& Size() const{
return sizeof(T)*length;
return sizeof(T)*Length();
}
void Peek() {
obj = &(*this);
Expand All @@ -199,23 +202,23 @@ template <class T, int N=-1> class Pointer {
void Resize(int newlength) {
// TODO: Clean up condition
static_assert(N != -1, "Can't grow non-arrays!");
if (length == newlength)
if (Length() == newlength)
return;
int oldindex = index;
int oldlength = length;
int oldlength = Length();
void* oldobj = mm::get().GetObject(oldindex, Size());
if (oldlength > newlength) {
for (int i = newlength; i < oldlength; ++i) {
mmDestroy((*this)[i]);
}
}
length = newlength;
SetLength(newlength);
index = mm::get().Allocate(Size());
void* newobj = mm::get().GetObject(index, Size());
memcpy(newobj, oldobj, oldlength < length ? (sizeof(T) + sizeof(int))*oldlength : (sizeof(T) + sizeof(int))*length);
memcpy(newobj, oldobj, oldlength < Length() ? (sizeof(T) + sizeof(int))*oldlength : (sizeof(T) + sizeof(int))*Length());
mm::get().Shred(oldindex, sizeof(T)*oldlength);
if (oldlength < length) {
for (int i = oldlength; i < length; ++i) {
if (oldlength < Length()) {
for (int i = oldlength; i < Length(); ++i) {
mmInitialize((*this)[i]);
}
}
Expand All @@ -224,7 +227,7 @@ template <class T, int N=-1> class Pointer {
if (count)
(*count)++;
}
if (length > 0) {
if (Length() > 0) {
destroyed = false;
}
else {
Expand All @@ -243,9 +246,9 @@ template <class T, int N=-1> class Pointer {
void Init(){
index = -1;
if (IsArray())
length = N;
SetLength(N);
else
length = 1;
SetLength(1);
}
~Pointer(){
Clear();
Expand All @@ -261,7 +264,7 @@ template <class T, int N=-1> class Pointer {
Pointer& operator=(const Pointer& param){
if (this == &param)
return *this;
length = param.Length();
SetLength(param.Length());
Set(param.GetIndex());
if (IsGood())
destroyed = false;
Expand All @@ -285,7 +288,7 @@ template <class T, int N=-1> class Pointer {
destroyed = false;
}
else {
for (int i = 0; i < length; ++i) {
for (int i = 0; i < Length(); ++i) {
mmInitialize<T>((*this)[i]);
mmRecursiveInitialize((*this)[i]);
destroyed = false;
Expand Down

0 comments on commit 04e7d18

Please sign in to comment.