blueloveTH 1 год назад
Родитель
Сommit
2929addbd8
3 измененных файлов с 6 добавлено и 6 удалено
  1. 1 1
      include/pocketpy/tuplelist.h
  2. 4 4
      include/pocketpy/vector.h
  3. 1 1
      src/dict.cpp

+ 1 - 1
include/pocketpy/tuplelist.h

@@ -7,7 +7,7 @@
 
 namespace pkpy {
 
-using List = pod_vector<PyObject*>;
+using List = pod_vector<PyObject*, 4>;
 
 struct Tuple {
     PyObject** _args;

+ 4 - 4
include/pocketpy/vector.h

@@ -5,7 +5,7 @@
 
 namespace pkpy{
 
-template<typename T>
+template<typename T, int Growth=2>
 struct pod_vector{
     static constexpr int SizeT = sizeof(T);
     static constexpr int N = 64 / SizeT;
@@ -60,13 +60,13 @@ struct pod_vector{
 
     template<typename __ValueT>
     void push_back(__ValueT&& t) {
-        if (_size == _capacity) reserve(_capacity*2);
+        if (_size == _capacity) reserve(_capacity*Growth);
         _data[_size++] = std::forward<__ValueT>(t);
     }
 
     template<typename... Args>
     void emplace_back(Args&&... args) {
-        if (_size == _capacity) reserve(_capacity*2);
+        if (_size == _capacity) reserve(_capacity*Growth);
         new (&_data[_size++]) T(std::forward<Args>(args)...);
     }
 
@@ -110,7 +110,7 @@ struct pod_vector{
 
     template<typename __ValueT>
     void insert(int i, __ValueT&& val){
-        if (_size == _capacity) reserve(_capacity*2);
+        if (_size == _capacity) reserve(_capacity*Growth);
         for(int j=_size; j>i; j--) _data[j] = _data[j-1];
         _data[i] = std::forward<__ValueT>(val);
         _size++;

+ 1 - 1
src/dict.cpp

@@ -66,7 +66,7 @@ namespace pkpy{
         ItemNode* old_nodes = _nodes;
         int old_head_idx = _head_idx;
 
-        _capacity *= 2;
+        _capacity *= 4;
         _mask = _capacity - 1;
         _size = 0;
         _critical_size = _capacity*__LoadFactor+0.5f;