blueloveTH 2 лет назад
Родитель
Сommit
3cae7e6809
3 измененных файлов с 6 добавлено и 6 удалено
  1. 1 0
      include/pocketpy/gc.h
  2. 5 5
      src/ceval.cpp
  3. 0 1
      src/gc.cpp

+ 1 - 0
include/pocketpy/gc.h

@@ -63,6 +63,7 @@ struct ManagedHeap{
 
     int sweep();
     void _auto_collect();
+    bool _should_auto_collect() const { return gc_counter >= gc_threshold; }
     int collect();
     void mark();
     ~ManagedHeap();

+ 5 - 5
src/ceval.cpp

@@ -82,7 +82,7 @@ __NEXT_STEP:;
         DISPATCH();
     /*****************************************/
     TARGET(LOAD_CONST)
-        heap._auto_collect();
+        if(heap._should_auto_collect()) heap._auto_collect();
         PUSH(co_consts[byte.arg]);
         DISPATCH();
     TARGET(LOAD_NONE) PUSH(None); DISPATCH();
@@ -105,13 +105,13 @@ __NEXT_STEP:;
     TARGET(LOAD_NULL) PUSH(PY_NULL); DISPATCH();
     /*****************************************/
     TARGET(LOAD_FAST) {
-        heap._auto_collect();
+        if(heap._should_auto_collect()) heap._auto_collect();
         _0 = frame->_locals[byte.arg];
         if(_0 == PY_NULL) vm->UnboundLocalError(co->varnames[byte.arg]);
         PUSH(_0);
     } DISPATCH();
     TARGET(LOAD_NAME) {
-        heap._auto_collect();
+        if(heap._should_auto_collect()) heap._auto_collect();
         _name = StrName(byte.arg);
         PyObject** slot = frame->_locals.try_get_name(_name);
         if(slot != nullptr) {
@@ -128,7 +128,7 @@ __NEXT_STEP:;
         vm->NameError(_name);
     } DISPATCH();
     TARGET(LOAD_NONLOCAL) {
-        heap._auto_collect();
+        if(heap._should_auto_collect()) heap._auto_collect();
         _name = StrName(byte.arg);
         _0 = frame->f_closure_try_get(_name);
         if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
@@ -139,7 +139,7 @@ __NEXT_STEP:;
         vm->NameError(_name);
     } DISPATCH();
     TARGET(LOAD_GLOBAL)
-        heap._auto_collect();
+        if(heap._should_auto_collect()) heap._auto_collect();
         _name = StrName(byte.arg);
         _0 = frame->f_globals().try_get_likely_found(_name);
         if(_0 != nullptr) { PUSH(_0); DISPATCH(); }

+ 0 - 1
src/gc.cpp

@@ -33,7 +33,6 @@ namespace pkpy{
     void ManagedHeap::_auto_collect(){
 #if !PK_DEBUG_NO_AUTO_GC
         if(_gc_lock_counter > 0) return;
-        if(gc_counter < gc_threshold) return;
         gc_counter = 0;
         collect();
         gc_threshold = gen.size() * 2;