コミットメタ情報

リビジョン4bf16172f09741942e4f2a42669ef176c9479ed9 (tree)
日時2018-10-11 05:19:59
作者Agustina Arzille <avarzille@rise...>
コミッターAgustina Arzille

ログメッセージ

Optimize serialization

変更サマリ

差分

diff -r 9ecb7c9f9491 -r 4bf16172f097 builtins.cpp
--- a/builtins.cpp Wed Oct 10 15:50:07 2018 -0300
+++ b/builtins.cpp Wed Oct 10 17:19:59 2018 -0300
@@ -56,15 +56,15 @@
5656 itype == typecode::TABLE ||
5757 itype == typecode::TREE ||
5858 itype == typecode::PKG ||
59- itype == typecode::SYMBOL ||
59+ itype == typecode::SYMBOL /* ||
6060 itype == typecode::BVECTOR ||
61- itype == typecode::STR);
61+ itype == typecode::STR */);
6262 }
6363
6464 int xserialize (interpreter *interp, stream *strm,
6565 object obj, serial_info& info)
6666 {
67- int ret = -2, idx = -1, tp = itype (obj);
67+ int ret = 0, idx = -1, tp = itype (obj);
6868
6969 if (tp < 0 || tp >= typecode::LAST)
7070 invalid_arg (interp, "serialize");
@@ -77,6 +77,18 @@
7777 return (strm->putb (interp, SERIAL_REF) +
7878 strm->write (interp, &idx));
7979 }
80+ else if (tp == typecode::CHAR && as_char (obj) <= 0xff)
81+ {
82+ unsigned char data[] = { SERIAL_BCHAR, (unsigned char)as_char (obj) };
83+ return (strm->write (interp, data, sizeof (data)));
84+ }
85+ else if (tp == typecode::INT && as_int (obj) <= 0xff)
86+ {
87+ unsigned char data[] = { SERIAL_BINT, (unsigned char)as_int (obj) };
88+ return (strm->write (interp, data, sizeof (data)));
89+ }
90+ else if (obj == NIL)
91+ return (strm->putb (interp, SERIAL_NIL));
8092
8193 ret += strm->putb (interp, tp);
8294 valref pos (interp, UNBOUND);
@@ -115,13 +127,17 @@
115127 #undef DISPATCH
116128 }
117129
118- if (!(idx < 0) && !((idx = info.del_ref (idx)) < 0))
119- { // XXX: Optimize for conses (too many seeks)
130+ if ((idx >= 0 && (idx = info.del_ref (idx)) >= 0) ||
131+ (tp == typecode::CONS && (idx = 0, true)))
132+ {
120133 valref p2 (interp, strm->tell (interp));
121134 if (!strm->seek (interp, *pos, SEEK_SET))
122135 return (-1);
123136
124137 strm->write (interp, &idx);
138+ if (tp == typecode::CONS)
139+ strm->write (interp, &info.output);
140+
125141 strm->seek (interp, *p2, SEEK_SET);
126142 }
127143
@@ -144,6 +160,14 @@
144160
145161 qp_return (info.find_id (tp));
146162 }
163+ else if (tp == SERIAL_BINT || tp == SERIAL_BCHAR)
164+ {
165+ int nb = strm->getb (interp);
166+ if (nb < 0)
167+ qp_return (UNBOUND);
168+
169+ qp_return (tp == SERIAL_BINT ? intobj (nb) : charobj (nb));
170+ }
147171
148172 info.output = 0;
149173 if (serial_ref_p (tp) && !strm->sread (interp, &info.output))
diff -r 9ecb7c9f9491 -r 4bf16172f097 cons.cpp
--- a/cons.cpp Wed Oct 10 15:50:07 2018 -0300
+++ b/cons.cpp Wed Oct 10 17:19:59 2018 -0300
@@ -434,7 +434,7 @@
434434 if (obj == NIL)
435435 return (strm->putb (interp, SERIAL_NIL));
436436
437- valref tmp (interp, obj), pos1 (interp, strm->tell (interp));
437+ valref tmp (interp, obj);
438438 int len = 0, ret = 0;
439439
440440 ret += strm->write (interp, &len);
@@ -455,12 +455,7 @@
455455 }
456456 }
457457
458- valref pos2 (interp, strm->tell (interp));
459- if (!strm->seek (interp, *pos1, SEEK_SET))
460- return (-1);
461-
462- strm->write (interp, &len);
463- strm->seek (interp, *pos2, SEEK_SET);
458+ info.output = len; // Let the caller know our length.
464459 return (ret);
465460 }
466461
diff -r 9ecb7c9f9491 -r 4bf16172f097 floatp.cpp
--- a/floatp.cpp Wed Oct 10 15:50:07 2018 -0300
+++ b/floatp.cpp Wed Oct 10 17:19:59 2018 -0300
@@ -130,9 +130,11 @@
130130 {
131131 sign = fneg_p (val);
132132 #ifdef QP_ARCH_WIDE
133- sign ^= varobj_sign (obj);
134- if (sign != 0)
135- val = -val;
133+ if (varobj_sign (obj))
134+ {
135+ sign ^= 1;
136+ val = -val;
137+ }
136138 #endif
137139 cls = FP_NORMAL;
138140 }
diff -r 9ecb7c9f9491 -r 4bf16172f097 io.h
--- a/io.h Wed Oct 10 15:50:07 2018 -0300
+++ b/io.h Wed Oct 10 17:19:59 2018 -0300
@@ -121,6 +121,8 @@
121121
122122 enum
123123 {
124+ SERIAL_BINT = 0xfa,
125+ SERIAL_BCHAR = 0xfb,
124126 SERIAL_REF = 0xfc,
125127 SERIAL_NIL = 0xfd,
126128 SERIAL_END = 0xfe
旧リポジトリブラウザで表示