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:
TermiNexus committed 2026-10-05 15:33:52 +08:00
1 parent 3e1ed0992b
commit 27121f56a7
27 files changed
+208 -534

No files matched your search

+9 -17
View File
@@ -76,10 +76,8 @@ def stream_pull(out: str, cap: INT) -> INT:
avail = INT(_st_len - _st_consumed)
if avail > cap - 1:
avail = cap - 1
i: sizet = 0
while i < sizet(avail):
for i in range(sizet(avail)):
out[i] = _st_buf[_st_consumed + i]
i += 1
out[sizet(avail)] = 0
_st_consumed += sizet(avail)
return avail
@@ -503,8 +501,7 @@ def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data:
return None
string.strcpy(cur, url)
hop: INT = 0
while hop < 5:
for hop in range(5):
resp: rawptr[requests.Response] = _HttpsRequest(method, cur, verify, ca_file, data, content_type, auth)
if resp is None:
requests._mbuddy.free(cur)
@@ -549,7 +546,6 @@ def _HttpsRedirectLoop(method: str, url: str, verify: bool, ca_file: str, data:
requests._mbuddy.free(loc)
requests._mbuddy.free(cur)
cur = nxt
hop += 1
_RecordErrorText("too many redirects")
requests._mbuddy.free(cur)
@@ -843,12 +839,10 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
while True:
# 找行尾 \n
nl: INT = -1
k: INT = 0
while k < llen:
for k in range(llen):
if leftover[k] == 10:
nl = k
break
k += 1
if nl < 0:
break
e: INT = nl
@@ -886,10 +880,8 @@ def post_stream(url: str, data: str, content_type: str = "application/json",
_StreamAppendContent(dtx)
# 3) 移除已处理行
rem: INT = llen - (nl + 1)
j2: INT = 0
while j2 < rem:
for j2 in range(rem):
leftover[j2] = leftover[nl + 1 + j2]
j2 += 1
llen = rem
# ---- 收尾 ----
@@ -938,8 +930,8 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
if url is None or dst is None or dst_cap <= 0 \
or out_status is None or out_total is None:
return -1
c.Set(*out_status, 0)
c.Set(*out_total, 0)
*out_status = 0
*out_total = 0
if out_loc is not None and out_loccap > 0:
out_loc[0] = 0
_last_verify_flag = 1 if verify else 0
@@ -1064,7 +1056,7 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
dst[total] = 0
st: INT = requests._StatusRaw(dst)
c.Set(*out_status, st)
*out_status = st
if st == 0:
_RecordErrorText("empty response")
return -3
@@ -1078,11 +1070,11 @@ def _DlOnce(url: str, start: sizet, count: INT, verify: bool, ca_file: str,
return -3
if st == 206:
c.Set(*out_total, requests._CRTotalOf(dst, total))
*out_total = requests._CRTotalOf(dst, total)
else:
cl2: INT = requests._CLenOf(dst, total)
if cl2 > 0:
c.Set(*out_total, sizet(cl2))
*out_total = sizet(cl2)
bo: INT = requests._FindBodyStart(dst, total)
if bo < 0 or bo >= total:
return 0