[#3747] constants (or class vriable?) — Wakou Aoyama <wakou@...>

青山です。

20 messages 1998/12/06
[#3751] Re: constants (or class vriable?) — Shin-ichro Hara <sinara@...> 1998/12/07

原です。

[#3763] Re: constants (or class vriable?) — Wakou Aoyama <wakou@...> 1998/12/07

青山です。

[#3764] Re: constants (or class vriable?) — matz@... (Yukihiro Matsumoto) 1998/12/08

まつもと ゆきひろです

[#3767] Re: constants (or class vriable?) — kjana@... (YANAGAWA Kazuhisa) 1998/12/08

In message <199812080034.JAA05946@picachu.netlab.co.jp>

[#3826] ruby 1.1d0 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

35 messages 1998/12/16

[#3873] (?: ) does not work? — shugo@... (MAEDA Shugo)

前田です。

15 messages 1998/12/19

[#3881] I want to catch all jump — shugo@... (Shugo Maeda)

前田です。

17 messages 1998/12/21
[#3895] Re: I want to catch all jump — matz@... (Yukihiro Matsumoto) 1998/12/22

まつもと ゆきひろです

[#3894] ruby 1.1d1 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

25 messages 1998/12/22

[#3899] interpreter reinitialization — shugo@... (Shugo Maeda)

前田です。

22 messages 1998/12/22
[#3923] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/23

まつもと ゆきひろです

[#3926] Re: interpreter reinitialization — shugo@... (Shugo Maeda) 1998/12/23

前田です。

[#3931] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/24

まつもと ゆきひろです

[#3956] Re: interpreter reinitialization — shugo@... (Shugo Maeda) 1998/12/24

前田です。

[#3960] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/24

まつもと ゆきひろです

[#4002] config.guess — Koji Arai <JCA02266@...>

新井です。

24 messages 1998/12/26
[#4039] Re: config.guess — matz@... (Yukihiro Matsumoto) 1998/12/29

まつもと ゆきひろです

[#4045] Re: config.guess — Koji Arai <JCA02266@...> 1998/12/31

新井です。

[#4047] Re: config.guess — matz@... (Yukihiro Matsumoto) 1999/01/01

まつもと ゆきひろです

[#4048] Re: config.guess — Koji Arai <JCA02266@...> 1999/01/01

新井です。

[#4049] Re: config.guess — matz@... (Yukihiro Matsumoto) 1999/01/02

まつもと ゆきひろです

[#4050] Re: config.guess — Motoyuki Kasahara <m-kasahr@...> 1999/01/04

笠原です。

[#4030] module Precision — gotoken@... (GOTO Kentaro)

ごとけんです

78 messages 1998/12/28
[#4310] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/21

ごとけんです

[#4311] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/01/21

まつもと ゆきひろです

[#4312] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/21

ごとけんです

[#4317] Re: module Precision — keiju@... (石塚圭樹 ) 1999/01/21

けいじゅ@日本ラショナルソフトウェアです.

[#4364] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/25

ごとけんです

[#4478] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/01/28

まつもと ゆきひろです

[#4506] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/30

ごとけんです

[#4552] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/02/01

まつもと ゆきひろです

[#4557] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/01

ごとけんです

[#4632] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4647] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/03

けいじゅ@日本ラショナルソフトウェアです.

[#4648] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4633] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/02/03

まつもと ゆきひろです

[#4636] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4836] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/08

ごとけんです

[#4843] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/08

けいじゅ@日本ラショナルソフトウェアです.

[#4849] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/08

ごとけんです

[#4924] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/09

けいじゅ@日本ラショナルソフトウェアです.

[#4976] a genericity — gotoken@... (GOTO Kentaro) 1999/02/10

ごとけんです

[#5008] Re: a genericity — keiju@... (石塚圭樹 ) 1999/02/11

けいじゅ@日本ラショナルソフトウェアです.

[#5018] Re: a genericity — gotoken@... (GOTO Kentaro) 1999/02/11

ごとけんです

[#5171] Re: a genericity — keiju@... (石塚圭樹 ) 1999/02/16

けいじゅ@日本ラショナルソフトウェアです.

[ruby-dev:3786] pack("m")

From: shugo@... (MAEDA Shugo)
Date: 1998-12-09 10:23:20 UTC
List: ruby-dev #3786
前田です。

>>>>> In [ruby-dev:3773]
>>>>> "前田" == MAEDA Shugo <shugo@aianet.ne.jp> san wrote:

前田> pack.cのencodes()は、ループの中で毎回str_cat()を呼ぶために、
前田> 何度もreallocするせいで少し遅いような気がするのですが、どうでしょう。

バッファリングするようにしたらかなり速くなりました:-)

$ time /usr/local/bin/ruby -e '[open("ruby").read].pack("m")'
real    0m3.651s
user    0m2.400s
sys     0m1.250s
$ time ./ruby -e '[open("ruby").read].pack("m")'

real    0m0.891s
user    0m0.750s
sys     0m0.140s

パッチを添付します。
あと、文字列の範囲外のメモリにアクセスしないように変更してあります。


-- 
前田 修吾 (mailto:shugo@aianet.ne.jp)

Attachments (1)

pack.c.diff (1.69 KB, text/x-diff)
--- pack.c.orig	Wed Dec  9 16:47:44 1998
+++ pack.c	Wed Dec  9 19:08:37 1998
@@ -513,38 +513,41 @@
     int len;
     int type;
 {
-    char hunk[4];
+    char *buff = ALLOCA_N(char, len * 4 / 3 + 6);
+    int i = 0;
     char *p, *pend;
     char *trans = type == 'u' ? uu_table : b64_table;
     int padding;
 
     if (type == 'u') {
-	*hunk = len + ' ';
-	str_cat(str, hunk, 1);
+	buff[i++] = len + ' ';
 	padding = '`';
     }
     else {
 	padding = '=';
     }
-    while (len > 0) {
-	hunk[0] = trans[077 & (*s >> 2)];
-	hunk[1] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
-	hunk[2] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
-	hunk[3] = trans[077 & s[2]];
-	str_cat(str, hunk, 4);
+    while (len >= 3) {
+	buff[i++] = trans[077 & (*s >> 2)];
+	buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
+	buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
+	buff[i++] = trans[077 & s[2]];
 	s += 3;
 	len -= 3;
     }
-    p = RSTRING(str)->ptr;
-    pend = RSTRING(str)->ptr + RSTRING(str)->len;
-    if (len == -1) {
-	pend[-1] = padding;
+    if (len == 2) {
+	buff[i++] = trans[077 & (*s >> 2)];
+	buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
+	buff[i++] = trans[077 & (((s[1] << 2) & 074) | (('\0' >> 6) & 03))];
+	buff[i++] = padding;
     }
-    else if (len == -2) {
-	pend[-2] = padding;
-	pend[-1] = padding;
+    else if (len == 1) {
+	buff[i++] = trans[077 & (*s >> 2)];
+	buff[i++] = trans[077 & (((*s << 4) & 060) | (('\0' >> 4) & 017))];
+	buff[i++] = padding;
+	buff[i++] = padding;
     }
-    str_cat(str, "\n", 1);
+    buff[i++] = '\n';
+    str_cat(str, buff, i);
 }
 
 static char hex_table[] = "0123456789ABCDEF";

In This Thread