refactor(includes): R12 下标 while 循环改 for range,R13 c.Set 迁移为赋值
R12(wiki/新规范 L27-39):把「i: int = 0 与 while i < N: … i += 1」形式的下标循环改写为「for i in range(N):」。保守判定:仅当条件为裸 NAME < EXPR、循环体无 continue、NAME 在体内无其它赋值、无嵌套重绑定、循环后同层不再引用 NAME 时才改写。共 269 处 / 48 文件。 R13:c.Set 是正在退化的路径——c.Set(*p, v) 期望写作 *p = v,c.Set(a, b) 等于 a = b。本次把 includes 内 45 处 c.Set 全部迁移为赋值,includes 已无 c.Set 调用。 验证:bootstrap 三重重编 SUCCESS(无 vast_c 解析回退);全量 77/77 顺序回归通过;ZlibTest 内部断言 79 passed / 0 failed。
This commit is contained in:
1 parent
3e1ed0992b
commit
27121f56a7
27 files changed
+208
-534
No files matched your search
+2
-6
@@ -104,8 +104,7 @@ class HashTable:
|
||||
mask: sizet = self.__capacity__ - 1
|
||||
idx: sizet = sizet(h) & mask
|
||||
first_tombstone: sizet = self.__capacity__
|
||||
i: sizet = 0
|
||||
while i < self.__capacity__:
|
||||
for i in range(self.__capacity__):
|
||||
sh: uint64 = self._slot_hash(idx)
|
||||
if sh == _HT_EMPTY:
|
||||
if first_tombstone < self.__capacity__:
|
||||
@@ -120,7 +119,6 @@ class HashTable:
|
||||
if string.strcmp(sk, key) == 0:
|
||||
return idx
|
||||
idx = (idx + 1) & mask
|
||||
i += 1
|
||||
if first_tombstone < self.__capacity__:
|
||||
return first_tombstone
|
||||
return self.__capacity__
|
||||
@@ -137,8 +135,7 @@ class HashTable:
|
||||
self.__capacity__ = new_cap
|
||||
self.__count__ = 0
|
||||
self.__tombstones__ = 0
|
||||
i: sizet = 0
|
||||
while i < old_cap:
|
||||
for i in range(old_cap):
|
||||
old_h_ptr: uint64* = t.CPtr(uint64(old_slots) + i * _HT_SLOT_SIZE)
|
||||
h: uint64 = old_h_ptr[0]
|
||||
if h != _HT_EMPTY and h != _HT_TOMBSTONE:
|
||||
@@ -150,7 +147,6 @@ class HashTable:
|
||||
idx: sizet = self._find_slot(k, h)
|
||||
self._set_slot(idx, h, k, v)
|
||||
self.__count__ += 1
|
||||
i += 1
|
||||
|
||||
def __setitem__(self, key: str, val: t.CNeedPtr):
|
||||
"""Insert or update key-value pair. val automatically decays to pointer (t.CNeedPtr: no conversion if already pointer)."""
|
||||
|
||||
Reference in new issue
Block a user