Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7031ca3
[moebius] tree_utf8_to_herk/tree_herk_to_utf8 原子节点加 ASCII 恒等快路径
da-liii Aug 19, 2026
c1d3f10
[moebius] correct_node 消除标签字符串绕行,新增 drd contains(tree_label) 重载
da-liii Aug 19, 2026
f0e2333
[moebius] gf fmt 格式化补漏
da-liii Aug 19, 2026
17a919d
[moebius] scaling/an_scaling 直变换逐分量直写,消除中间 point 临时分配
da-liii Aug 19, 2026
c8b5ba8
[moebius] gf fmt 格式化补漏
da-liii Aug 19, 2026
469e0f9
[moebius] segment/poly_segment 求值与 rotate_2D 逐分量直写,消除中间 point 临时
da-liii Aug 19, 2026
6a578d4
[moebius] spline 求值 interval_no 缓存并跳过单位标量乘
da-liii Aug 19, 2026
27611d8
[moebius] raw_split/raw_join 逐元素搬移改为 memmove 块移动
da-liii Aug 19, 2026
64d6c81
[moebius] get_env_child 空环境快路径,免去 ATTR 构造与合并
da-liii Aug 19, 2026
fafd560
[moebius] can_* 适用性检查单趟下探,免去 has_subtree+subtree 双遍历
da-liii Aug 19, 2026
1cf4b2d
[moebius] move_any 单趟下探,免去三次 subtree 重复全树下探
da-liii Aug 19, 2026
feda483
[moebius] tmu_reader::read_next 字节级扫描,消除逐字符子串分配
da-liii Aug 19, 2026
96300fa
[moebius] 三对角求解逐分量就地写,消除每行 point 临时分配
da-liii Aug 19, 2026
687b0d3
[moebius] scheme 解析器修复词元/引号/unslash 三处越界读,CR 替换改先探测
da-liii Aug 19, 2026
7cd60ea
[moebius] slash/scm_quote 序列化成段追加,消除逐字符 resize
da-liii Aug 19, 2026
d75371c
[moebius] move_word 单趟下探与 tm_codepoint_at 原串解析,消除逐字符子串分配
da-liii Aug 19, 2026
b98df7d
[moebius] simplify_correct 未变子树共享原节点,免去标记节点重建
da-liii Aug 19, 2026
b9296ce
[moebius] .tm 加载跳过 flag 路径的 codes 查表,scm_unquote 成段追加
da-liii Aug 19, 2026
e45df05
[moebius] 曲线最近点搜索与求交消除差向量临时 point
da-liii Aug 19, 2026
f2510e9
[moebius] arc/ellipse 求值与梯度逐分量直写,消除 2-4 个中间 point 临时
da-liii Aug 19, 2026
c9444a5
[moebius] bezier 求值/梯度/取直逐分量直写,消除链式 point 临时
da-liii Aug 19, 2026
4597a42
[moebius] hyperbola/parabola 求值与梯度逐分量直写,消除链式 point 临时
da-liii Aug 19, 2026
65e70e6
[moebius] 补回 parabola 测试:上轮 SIGSEGV 实为 fixture 的 point int 字面量构造陷阱
da-liii Aug 19, 2026
64238a0
[moebius] keep_positive 无负索引快路径,免去光标校正的整条 path 重建
da-liii Aug 19, 2026
418408c
[moebius] 任务文档补全量复测成绩单(24 测试全过、21 项优化、5 项负结果)
da-liii Aug 19, 2026
796e491
[moebius] EXTERN 派生标签单条备忘缓存,免去热路径字符串拼接与查表
da-liii Aug 19, 2026
38343da
[moebius] tmu_reader::decode 成段追加,标签分支免去 make_tree_label 双查表
da-liii Aug 19, 2026
b071a11
[moebius] end(t,p) 复用父节点引用,免去 subtree 第二次全树下探
da-liii Aug 19, 2026
1cb02d5
[moebius] frame::enclose 采样插值逐分量直写,消除三个中间 point 临时
da-liii Aug 19, 2026
d803660
[moebius] inside_contiguous_document 边界祖先单趟下探,O(depth^2) 改 O(depth)
da-liii Aug 19, 2026
6ddfd0f
[moebius] tmu_reader::read_apply 同法免去 make_tree_label 双查表
da-liii Aug 19, 2026
6498895
[moebius] get_env_child WITH 快路径直扫绑定对,免去子树拷贝与 env 合并重建
da-liii Aug 19, 2026
6b4765c
[moebius] get_env_child env 变体 WITH 分支免子树拷贝,原树直迭绑定对
da-liii Aug 19, 2026
b0a43de
[moebius] drd_env_write 单次分配重建,追加/插入/替换免五连树分配
da-liii Aug 19, 2026
26cc046
[moebius] 移除已禁用的 next_without_border 死调用与函数体
da-liii Aug 19, 2026
aa2e160
[moebius] 第 34 轮验证轮:s7/object 胶水层评估结论与全量回归记录
da-liii Aug 19, 2026
cf33e20
[moebius] 原子文本编辑单次分配 memcpy 拼接,打字路径 2.03x
da-liii Aug 19, 2026
29a334d
[moebius] tmu_writer::write 成段 memcpy 直写,写路径 1.43x
da-liii Aug 19, 2026
fe531fa
[moebius] slash/scm_quote 升级为 resize+memcpy 直写,序列化 1.13-1.22x
da-liii Aug 19, 2026
1fe4e24
[moebius] memcpy 直写回补 tmu 读路径与 scm_unquote,读路径再 1.08-1.13x
da-liii Aug 19, 2026
533b38d
[moebius] 成绩单补录 5.22-5.35 共 14 项
da-liii Aug 19, 2026
cb715e8
[moebius] colors 基准与 named_color 双重小写化负结果记录
da-liii Aug 19, 2026
4d5c0cd
[moebius] 第 41 轮:rel_hashmap 双探测合一放弃评估与验证记录
da-liii Aug 19, 2026
e25dd83
[moebius] commute 换位语义测试与基准;swap1 重写负结果记录
da-liii Aug 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
678 changes: 678 additions & 0 deletions devel/moebius.md

Large diffs are not rendered by default.

131 changes: 84 additions & 47 deletions moebius/Data/Convert/tmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ using lolly::data::to_Hex;
using moebius::drd::STD_CODE;
using moebius::drd::std_contains;

// 成段 memcpy 直写目标串(定义见 tmu_writer::write 前)
static void append_run (string& tmp, const char* src, int len);

using namespace moebius;

/******************************************************************************
Expand Down Expand Up @@ -285,17 +288,21 @@ tmu_reader::skip_blank () {

string
tmu_reader::decode (string s) {
int i, n= N (s);
string r;
// 普通字符成段 memcpy 直写,转义字符单独处理
int i, n= N (s), run= 0;
string r;
const char* raw= s.begin ();
for (i= 0; i < n; i++)
if (((i + 1) < n) && (s[i] == '\\')) {
append_run (r, raw + run, i - run);
i++;
if (s[i] == ';')
;
else if (s[i] == '\\') r << '\\';
else r << s[i];
run= i + 1;
}
else r << s[i];
append_run (r, raw + run, n - run);
return r;
}

Expand Down Expand Up @@ -352,28 +359,40 @@ tmu_reader::read_next () {
}

string r;
pos= old_pos;
while (true) {
old_pos= pos;
c = read_char ();
if (c == "") return r;
else if (c == "\\") {
if ((pos < buf_N) && (buf[pos] == '\\')) {
r << c << "\\";
pos++;
// 字节级扫描代替逐字符 read_char:普通字符成段一次追加,
// 转义 '\\' 逐字保留并连同后续一个 utf8 序列一起复制,
// 免去原文档加载热路径上每字符一次的子串分配
pos = old_pos;
int run= pos;
while (pos < buf_N) {
char b= buf[pos];
if (b == '\t' || b == '\r' || b == '\n' || b == ' ' || b == '<' ||
b == '|' || b == '>')
break;
if (b == '\\') {
append_run (r, buf.begin () + run, pos - run);
// 行续接 "\<newline>" 由 read_char 语义跳过
if ((pos + 1 < buf_N) && (buf[pos + 1] == '\n')) {
pos+= 2;
skip_spaces (buf, pos);
run= pos;
continue;
}
r << b;
pos++;
if (pos >= buf_N) {
run= pos;
break;
}
else r << c << read_char ();
int start= pos;
decode_from_utf8 (buf, pos);
append_run (r, buf.begin () + start, pos - start);
run= pos;
continue;
}
else if (c == "\t") break;
else if (c == "\r") break;
else if (c == "\n") break;
else if (c == " ") break;
else if (c == "<") break;
else if (c == "|") break;
else if (c == ">") break;
else r << c;
decode_from_utf8 (buf, pos);
}
pos= old_pos;
append_run (r, buf.begin () + run, pos - run);
return r;
}

Expand Down Expand Up @@ -402,12 +421,10 @@ get_collection (tree& u, tree t) {
tree
tmu_reader::read_apply (string name, bool skip_flag) {
// cout << "Read apply " << name << INDENT << LF;
tree t (make_tree_label (name));
if (codes->contains (name)) {
// cout << " " << name << " -> " << as_string ((tree_label) codes [name])
// << "\n";
t= tree ((tree_label) codes[name]);
}
// codes 命中时免去 make_tree_label 的构造与查表(与 read 同法)
tree t;
if (codes->contains (name)) t= tree ((tree_label) codes[name]);
else t= tree (make_tree_label (name));

bool closed= !skip_flag;
int buf_N = N (buf);
Expand Down Expand Up @@ -511,12 +528,10 @@ tmu_reader::read (bool skip_flag) {
C << read_apply (name, false);
}
else {
tree t (make_tree_label (name));
if (codes->contains (name)) {
// cout << name << " -> " << as_string ((tree_label) codes [name])
// << "\n";
t= tree ((tree_label) codes[name]);
}
// codes 命中时免去 make_tree_label 的构造与查表
tree t;
if (codes->contains (name)) t= tree ((tree_label) codes[name]);
else t= tree (make_tree_label (name));
C << t;
}
}
Expand Down Expand Up @@ -593,8 +608,9 @@ tmu_writer::cr () {
for (i= n - 1; i >= 0; i--)
if ((buf[i] != ' ') || ((i > 0) && (buf[i - 1] == '\\'))) break;
if (i < n - 1) {
buf= buf (0, i + 1);
n = n - N (buf);
// 原地截断代替整段前缀拷贝:buf 由 writer 独占,rep 引用计数为 1
buf->resize (i + 1);
n= n - N (buf);
for (i= 0; i < n; i++)
buf << "\\ ";
}
Expand Down Expand Up @@ -642,23 +658,44 @@ tmu_writer::write_return () {
ret_flag= true;
}

// 普通字符成段直写 tmp(resize + memcpy,无子串分配),
// 转义字符单独写入——逐字符 << 与逐字符下标写都有每次调用的额外开销
static void
append_run (string& tmp, const char* src, int len) {
if (len <= 0) return;
int old_n= N (tmp);
tmp->resize (old_n + len);
memcpy (tmp.begin () + old_n, src, len);
}

void
tmu_writer::write (string s, bool flag, bool encode_space) {
if (flag) {
int i, n= N (s);
int i, n= N (s), run= 0;
bool any= false; // 是否写入了实际字符(决定 spc/ret 标志)
const char* raw= s.begin ();
for (i= 0; i < n; i++) {
char c= s[i];
if ((c == ' ') && (!encode_space)) write_space ();
else {
if (c == ' ') tmp << "\\ ";
else if (c == '\\') tmp << "\\\\";
else if (c == '<') tmp << "\\<";
else if (c == '|') tmp << "\\|";
else if (c == '>') tmp << "\\>";
else tmp << c;
spc_flag= false;
ret_flag= false;
if ((c == ' ') && (!encode_space)) {
if (i > run) any= true;
append_run (tmp, raw + run, i - run);
run= i + 1;
write_space ();
}
else if (c == ' ' || c == '\\' || c == '<' || c == '|' || c == '>') {
if (i > run) any= true;
append_run (tmp, raw + run, i - run);
tmp << "\\";
tmp << c;
any= true;
run= i + 1;
}
}
if (n > run) any= true;
append_run (tmp, raw + run, n - run);
if (any) {
spc_flag= false;
ret_flag= false;
}
}
else {
Expand Down
37 changes: 20 additions & 17 deletions moebius/Data/Tree/tree_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,8 @@ is_modified_accessible (tree t, path p, bool activate, bool persistent) {
}
}

static bool
next_without_border (tree t, path p) {
return false;
// Assuming that t is a concat, check whether p does not correspond
// to an inaccessible border position
int i= p->item + 1;
if (i >= N (t)) return false;
if (is_compound (t[i]) && the_drd->is_child_enforcing (t[i]))
return p->next == end (t[p->item]);
return false;
}
// next_without_border 已被上游禁用(恒 false 的桩),其三处调用与
// 函数体已一并移除;原始逻辑见 git 历史与本任务 devel/moebius.md

static int
lowest_accessible_child (tree t) {
Expand Down Expand Up @@ -162,8 +153,8 @@ is_accessible_cursor (tree t, path p) {
return false;
else switch (L (t)) {
case CONCAT:
if (!is_accessible_cursor (t[p->item], p->next)) return false;
else return !next_without_border (t, p);
// next_without_border 已被上游禁用(恒 false),调用移除
return is_accessible_cursor (t[p->item], p->next);
case ACTIVE:
return is_modified_accessible (t, p, true, false);
case VAR_ACTIVE:
Expand Down Expand Up @@ -248,7 +239,7 @@ closest_accessible (tree t, path p, int dir) {
path r = closest_accessible (t[j], sp2, sdir);
if (!is_nil (r)) {
r= path (j, r);
if (!is_concat (t) || !next_without_border (t, r)) {
if (!is_concat (t)) {
if (the_drd->is_parent_enforcing (t) && !graphics_in_path (t, p) &&
!is_accessible_cursor (t, p)) {
if (r->item == lowest_accessible_child (t)) return path (0);
Expand Down Expand Up @@ -336,7 +327,7 @@ valid_cursor (tree t, path p, bool start_flag) {
p->next == end (t[p->item]))))
return false;
if (is_concat (t)) {
if (next_without_border (t, p)) return false;
// next_without_border 已被上游禁用(恒 false),调用移除
return valid_cursor (t[p->item], p->next, start_flag || (p->item != 0));
}
if (is_mod_active_once (t)) return is_atomic (t[0]) || (!is_atom (p->next));
Expand Down Expand Up @@ -492,6 +483,14 @@ right_correct (tree t, path p) {

static path
keep_positive (path p) {
// 常见情况全为非负索引:原样返回,免去逐层递归重建
bool has_neg= false;
for (path q= p; !is_nil (q); q= q->next)
if (q->item < 0) {
has_neg= true;
break;
}
if (!has_neg) return p;
if (is_nil (p)) return p;
if (p->item < 0) return path ();
return path (p->item, keep_positive (p->next));
Expand Down Expand Up @@ -520,8 +519,12 @@ start (tree t, path p) {
path
end (tree t, path p) {
// cout << "End " << p << " in " << t << "\n";
if ((!is_nil (p)) && (arity (parent_subtree (t, p)) == 0)) return p;
return correct_cursor (t, p * right_index (subtree (t, p)));
if (is_nil (p)) return correct_cursor (t, path (right_index (t)));
// 父节点已下探取得,其第 last_item(p) 个孩子即 p 所指节点,
// 免去 subtree 的第二次全树下探
tree& par= parent_subtree (t, p);
if (N (par) == 0) return p;
return correct_cursor (t, p * right_index (par[last_item (p)]));
}

path
Expand Down
26 changes: 20 additions & 6 deletions moebius/Data/Tree/tree_modify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,27 @@ tree
simplify_correct (tree t) {
if (is_atomic (t)) return t;
if (is_func (t, QUOTE, 1) && (is_atomic (t[0]))) return t[0];
int i, n= N (t);
int i, n= N (t);
if (is_concat (t) || is_document (t)) {
// concat/document 需要合并/展平,维持原有重建逻辑
tree r (t, n);
for (i= 0; i < n; i++)
r[i]= simplify_correct (t[i]);
if (is_concat (r)) r= simplify_concat (r);
if (is_document (r)) r= simplify_document (r);
return r;
}
// 其他复合节点:递归结果暂存,全部孩子共享原 rep 时免去新节点分配
array<tree> tmp (n);
bool changed= false;
for (i= 0; i < n; i++) {
tmp[i]= simplify_correct (t[i]);
if (!strong_equal (tmp[i], t[i])) changed= true;
}
if (!changed) return t;
tree r (t, n);
for (i= 0; i < n; i++)
r[i]= simplify_correct (t[i]);
if (is_concat (r)) r= simplify_concat (r);
if (is_document (r)) r= simplify_document (r);
r[i]= tmp[i];
return r;
}

Expand Down Expand Up @@ -127,8 +142,7 @@ correct_node (tree& t) {
// NOTE: this routine should only modify t and its descendants,
// but not any ancestors
if (is_compound (t)) {
if (the_drd->contains (as_string (L (t))) &&
!the_drd->correct_arity (L (t), N (t)))
if (the_drd->contains (L (t)) && !the_drd->correct_arity (L (t), N (t)))
assign (t, "");
if (is_concat (t)) correct_concat_node (t, 0);
}
Expand Down
Loading
Loading