little refactor

This commit is contained in:
2016-12-11 13:32:21 +07:00
parent d74728b4df
commit 8cff61ae91
21 changed files with 1447 additions and 448 deletions

View File

@@ -42,7 +42,7 @@ namespace IsoTools.Internal {
return false;
}
_dict.Add(item, _list.Count);
_list.Push(item);
_list.Add(item);
return true;
}
@@ -60,6 +60,12 @@ namespace IsoTools.Internal {
return false;
}
public T Pop() {
var item = _list.Pop();
_dict.Remove(item);
return item;
}
public void Clear() {
_list.Clear();
_dict.Clear();

View File

@@ -26,7 +26,7 @@ namespace IsoTools.Internal {
}
}
public void Push(T value) {
public void Add(T value) {
if ( _size == _data.Length ) {
var new_capacity = _size == 0
? _defaultCapacity : _size * 2;

View File

@@ -1,6 +1,4 @@
using System;
namespace IsoTools.Internal {
namespace IsoTools.Internal {
public interface IsoIPool<T> {
T Take();
void Release(T item);
@@ -12,7 +10,7 @@ namespace IsoTools.Internal {
public IsoPool(int capacity) {
_items = new IsoList<T>(capacity);
for ( var i = 0; i < capacity; ++i ) {
_items.Push(CreateItem());
_items.Add(CreateItem());
}
}
@@ -23,11 +21,8 @@ namespace IsoTools.Internal {
}
public void Release(T item) {
if ( item == null ) {
throw new ArgumentNullException("item");
}
CleanUpItem(item);
_items.Push(item);
_items.Add(item);
}
public abstract T CreateItem();

View File

@@ -562,7 +562,7 @@ namespace IsoTools {
_sectors.Capacity = count;
}
while ( _sectors.Count < _sectors.Capacity ) {
_sectors.Push(new Sector());
_sectors.Add(new Sector());
}
}
for ( int i = 0, e = _sectors.Count; i < e; ++i ) {
@@ -581,7 +581,7 @@ namespace IsoTools {
for ( var x = min.x; x < max.x; ++x ) {
var sector = FindSector(x, y);
if ( sector != null ) {
sector.objects.Push(iso_object);
sector.objects.Add(iso_object);
}
}}
}