[Mew-dist 1153] IM official patch 1

Kazu Yamamoto ( 山本和彦 ) Kazu at example.com
1997年 7月 2日 (水) 10:16:20 JST


Mr. Utashiro, a master of Perl, casted a spell to IM scripts to make
them faster once before. He said that he was not crazy about speed,
but he casted the spell again(probably "Programs MAY be faster!..." or
something). :)

Apply the following patch in IM.in directory. It will make 'imls'
about 30% faster than before, I bet.

--Kazu

*** Scan.pm.in.orig	Tue Jul  1 13:14:06 1997
--- Scan.pm.in	Tue Jul  1 13:58:13 1997
***************
*** 287,293 ****
  }
  
  sub disp_msg {
! 	my($href, $vscan) = @_;
  
  	${$href}{'indent-subject'} = ${$href}{'indent'} . ${$href}{'subject'};
  
--- 287,293 ----
  }
  
  sub disp_msg {
! 	(local $href, my $vscan) = @_;
  
  	${$href}{'indent-subject'} = ${$href}{'indent'} . ${$href}{'subject'};
  
***************
*** 295,305 ****
  		print &my_get_msg($href), "\n";
  		flush(STDOUT);
  		return;
! 	} elsif ($EVAL_SCAN_FORM) {
! 		my $content = eval($EVAL_SCAN_FORM);
  		if ($vscan) {
  			print &substr_safe($content, $WIDTH - 1), 
! 				eval($EVAL_VSCAN_FORM),	"\n";
  		} else {
  			print &substr_safe($content, $WIDTH - 1), "\n";
  		}
--- 295,305 ----
  		print &my_get_msg($href), "\n";
  		flush(STDOUT);
  		return;
! 	} elsif (defined(&scan_form)) {
! 		my $content = &scan_form;
  		if ($vscan) {
  			print &substr_safe($content, $WIDTH - 1), 
! 				&scan_form, "\n";
  		} else {
  			print &substr_safe($content, $WIDTH - 1), "\n";
  		}
***************
*** 379,384 ****
--- 379,388 ----
      $WIDTH = $width;
      $JIS_SAFE= $jis_safe;
      $EVAL_SCAN_FORM = convert_scan_form($scan_form);
+     eval "sub scan_form { $EVAL_SCAN_FORM }";
+     if ($@) {
+ 	im_die("Form seems to be wrong.\nPerl error message is: $@");
+     }
  }
  
  ############################################
*** MIME.pm.in.orig	Fri Jun 27 21:59:59 1997
--- MIME.pm.in	Tue Jul  1 22:37:58 1997
***************
*** 65,101 ****
  ## Variables
  ## 
  
! @c256to64 = ("A", "B", "C", "D", "E", "F", "G", "H", 
! 		 "I", "J", "K", "L", "M", "N", "O", "P",
! 		 "Q", "R", "S", "T", "U", "V", "W", "X",
! 		 "Y", "Z", "a", "b", "c", "d", "e", "f", 
! 		 "g", "h", "i", "j", "k", "l", "m", "n",
! 		 "o", "p", "q", "r", "s", "t", "u", "v", 
! 		 "w", "x", "y", "z", "0", "1", "2", "3", 
! 		 "4", "5", "6", "7", "8", "9", "+", "/");
! 
! $c64to256 = {
! 	'A' =>  0, 'B' =>  1, 'C' =>  2, 'D' =>  3, 
! 	'E' =>  4, 'F' =>  5, 'G' =>  6, 'H' =>  7, 
! 	'I' =>  8, 'J' =>  9, 'K' => 10, 'L' => 11, 
! 	'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 
! 	'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 
! 	'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 
! 	'Y' => 24, 'Z' => 25, 'a' => 26, 'b' => 27, 
! 	'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, 
! 	'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 
! 	'k' => 36, 'l' => 37, 'm' => 38, 'n' => 39, 
! 	'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 
! 	's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 
! 	'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 
! 	'0' => 52, '1' => 53, '2' => 54, '3' => 55, 
! 	'4' => 56, '5' => 57, '6' => 58, '7' => 59, 
! 	'8' => 60, '9' => 61, '+' => 62, '/' => 63, 
! 	'=' =>  0,
! };
! 
! @D2H = ("0", "1", "2", "3", "4", "5", "6", "7",
!  	 "8", "9", "A", "B", "C", "D", "E", "F");
  
  ##################################################
  ##
--- 65,71 ----
  ## Variables
  ## 
  
! @D2H = ('0'..'9', 'A'..'F');
  
  ##################################################
  ##
***************
*** 206,263 ****
  ## 
  
  sub b_encode_string {
! 	my($str256) = @_;
! 	my($rest) = (length($str256) % 3);
! 	my($count, $ret) = (0, "");
! 	my($c1, $c2, $c3, $len);
! 	
! 	if ($rest == 1) {
! 		$str256 = $str256 . chr(0) . chr(0); 
! 	} elsif ($rest == 2) {
! 		$str256 = $str256 . chr(0);
! 	}
  
! 	$len = length($str256);
! 	while ($count < $len) {
! 		($c1, $c2, $c3) = unpack("CCC", substr($str256, $count, 3));
! 		$ret = $ret . $c256to64[($c1>>2)] . 
! 			$c256to64[(($c1&0x03)<<4) + ($c2>>4)] . 
! 			$c256to64[(($c2&0x0f)<<2) + ($c3>>6)] . 
! 			$c256to64[($c3&0x3f)];
! 		$count = $count + 3;
! 	}
  
! 	if ($rest == 0) {
! 		return($ret);
! 	} elsif ($rest == 1) {
! 		return(substr($ret, 0, -2) . "==");
! 	} elsif ($rest == 2) {
! 		return(substr($ret, 0, -1) . "=");
! 	}
  }
  
  sub b_decode_string {
! 	my($str64) = @_;
! 	my($count, $ret, $len) = (0, "", length($str64));
! 	my($c1, $c2, $c3, $c4);
! 
! 	while ($count < $len) {
! 		$c1 = $$c64to256{substr($str64, $count, 1)};
! 		$c2 = $$c64to256{substr($str64, $count + 1, 1)};
! 		$c3 = $$c64to256{substr($str64, $count + 2, 1)};
! 		$c4 = $$c64to256{substr($str64, $count + 3, 1)};
! 		$ret = $ret . 
! 			chr(($c1<<2) + ($c2>>4)) . 
! 			chr(($c2<<4) + ($c3>>2)) . 
! 			chr(($c3<<6) + ($c4));
! 		$count = $count + 4;
! 	}
  
! 	if ($str64 =~ /^[^=]*(=+)$/) {
! 		return substr($ret, 0, - length($1));
! 	} else {
! 		return $ret;
  	}
  }
  
  ##################################################
--- 176,213 ----
  ## 
  
  sub b_encode_string {
! 	my $mod3 = length($_[0]) % 3;
! 	local($_);
  
! 	$_ = pack('u', $_[0]);
! 	chop;
! 	s/(^|\n).//mg;
! 	tr[`!-_][A-Za-z0-9+/];
  
! 	if    ($mod3 == 1) { s/..$/==/; }
! 	elsif ($mod3 == 2) { s/.$/=/; }
! 
! 	$_;
  }
  
  sub b_decode_string {
! 	my $s64 = shift;
! 	my $len;
! 	my $res = '';
! 	local($_);
! 
! 	while ($s64 =~ s/^.{1,60}//) {
! 		$_ = $&;
! 		
! 		$len = length($_) * 3 / 4;
! 		if (/=+$/) {
! 			$len -= length($&);
! 		}
! 		tr[A-Za-z0-9+/=][`!-_A];
  
! 		$res .= sprintf("%c%s\n", $len + 32, $_);
  	}
+ 	unpack('u', $res);
  }
  
  ##################################################




Mew-dist メーリングリストの案内