[Ttssh2-commit] [5466] 1MB以上のサイズを持つマクロファイルに対して、マクロ実行が極端に遅くなる問題を修正した。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2014年 1月 19日 (日) 00:01:24 JST


Revision: 5466
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5466
Author:   yutakapon
Date:     2014-01-19 00:01:23 +0900 (Sun, 19 Jan 2014)
Log Message:
-----------
1MB以上のサイズを持つマクロファイルに対して、マクロ実行が極端に遅くなる問題を修正した。
cf.
http://logmett.com/forum/viewtopic.php?f=3&t=2435
Macros Delayed 60 Seconds Before Starting 

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/ja/html/about/history.html
    trunk/teraterm/ttpmacro/ttmbuff.c

-------------- next part --------------
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2014-01-07 12:56:37 UTC (rev 5465)
+++ trunk/doc/en/html/about/history.html	2014-01-18 15:01:23 UTC (rev 5466)
@@ -41,6 +41,7 @@
     <ul>
       <li>When the window size is changed, the cursor moves to the left margin.</li>
       <li>The "Include screen buffer" option appears in the "Send file" and "ZMODEM Send" dialog.</li>
+      <li>MACRO: A macro file larger than 1MB slows down the performance.</li>
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2014-01-07 12:56:37 UTC (rev 5465)
+++ trunk/doc/ja/html/about/history.html	2014-01-18 15:01:23 UTC (rev 5466)
@@ -41,6 +41,7 @@
     <ul>
       <li>\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x95ύX\x82\xB5\x82\xBD\x8E\x9E\x82ɃJ\x81[\x83\\x83\x8B\x82\xAA\x8D\xB6\x92[\x82Ɉړ\xAE\x82\xB7\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
       <li>Send file\x83_\x83C\x83A\x83\x8D\x83O\x82\xC6ZMODEM Send\x83_\x83C\x83A\x83\x8D\x83O\x82\xC9"Include screen buffer"\x83I\x83v\x83V\x83\x87\x83\x93\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
+      <li>1MB\x88ȏ\xE3\x82̃T\x83C\x83Y\x82\xF0\x8E\x9D\x82ƒ}\x83N\x83\x8D\x83t\x83@\x83C\x83\x8B\x82ɑ΂\xB5\x82āA\x83}\x83N\x83\x8D\x8E\xC0\x8Ds\x82\xAA\x8Bɒ[\x82ɒx\x82\xAD\x82Ȃ\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
     </ul>
   </li>
 

Modified: trunk/teraterm/ttpmacro/ttmbuff.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmbuff.c	2014-01-07 12:56:37 UTC (rev 5465)
+++ trunk/teraterm/ttpmacro/ttmbuff.c	2014-01-18 15:01:23 UTC (rev 5466)
@@ -6,6 +6,7 @@
 
 #include "teraterm.h"
 #include <string.h>
+#include <stdlib.h>
 #include "ttmparse.h"
 #include "ttlib.h"
 
@@ -28,6 +29,11 @@
 static BINT BuffLen[MAXNESTLEVEL];
 static BINT BuffPtr[MAXNESTLEVEL];
 
+// \x8Ds\x8F\xEE\x95\xF1\x94z\x97\xF1
+#define MAX_LINENO 100000
+static BINT *BuffLineNo[MAXNESTLEVEL];
+static BINT BuffLineNoMaxIndex[MAXNESTLEVEL];
+
 #define MAXSP 10
 
 // Control type
@@ -92,6 +98,7 @@
 	int F;
 	int dummy_read = 0;
 	char basename[MAX_PATH];
+	unsigned int i, n;
 
 	if ((FileName[0]==0) || (IBuff>MAXNESTLEVEL-1)) {
 		return FALSE;
@@ -123,6 +130,10 @@
 		return FALSE;
 	}
 
+	if (BuffLineNo[IBuff] == NULL) {
+		BuffLineNo[IBuff] = malloc(MAX_LINENO * sizeof(BINT));
+	}
+
 	F = _lopen(FileName,OF_READ);
 	if (F<=0) {
 		return FALSE;
@@ -137,6 +148,30 @@
 				Buff[IBuff][1] = '\0';
 			}
 			_lclose(F);
+
+			// \x8Ds\x94ԍ\x86\x94z\x97\xF1\x82\xF0\x8D\xEC\x82\xE9\x81B\x82\xB1\x82\xEA\x82ɂ\xE6\x82\xE8\x81A\x83o\x83b\x83t\x83@\x82̃C\x83\x93\x83f\x83b\x83N\x83X\x82\xA9\x82\xE7\x8Ds\x94ԍ\x86\x82ւ̕ϊ\xB7\x82\xAA
+			// O(N)->O(logN)\x82Ō\x9F\x8D\xF5\x82ł\xAB\x82\xE9\x82悤\x82ɂȂ\xE9\x81B
+			// (2014.1.18 yutaka)
+			n = 0;
+			BuffLineNo[IBuff][n] = 0;
+			for (i = 0 ; i < BuffLen[IBuff] ; i++) {
+				if (Buff[IBuff][i] == 0x0A) {
+					if (i == BuffLen[IBuff] - 1) {
+						// \x83o\x83b\x83t\x83@\x82̍Ōオ\x89\xFC\x8Ds\x83R\x81[\x83h\x82\xBE\x82\xC1\x82\xBD\x8Fꍇ\x81A\x82\xE0\x82\xA4\x8E\x9F\x82̍s\x94ԍ\x86\x82͑\xB6\x8D݂\xB5\x82Ȃ\xA2\x81B
+
+					} else {
+						if (n < MAX_LINENO - 1) {
+							n++;
+							BuffLineNo[IBuff][n] = i + 1;
+						} else {
+							// Out of memory
+
+						}
+					}
+				}
+			}
+			BuffLineNoMaxIndex[IBuff] = n;
+
 			GlobalUnlock(BuffHandle[IBuff]);
 			return TRUE;
 		}
@@ -159,18 +194,18 @@
 
 
 // \x8C\xBB\x8Dݎ\xC0\x8Ds\x92\x86\x82̃}\x83N\x83\x8D\x83t\x83@\x83C\x83\x8B\x82̍s\x94ԍ\x86\x82\xF0\x95Ԃ\xB7 (2005.7.18 yutaka)
-static int getCurrentLineNumber(CHAR *buf, BINT curpos)
+static int getCurrentLineNumber(BINT curpos, BINT *lineno, BINT linenomax)
 {
-	int no;
-	BINT i;
+	BINT i, no;
 
 	no = 0;
-	for (i = 0 ; i < curpos ; i++) {
-		if (buf[i] == 0x0A) { // LF
-			no++;
+	for (i = 0 ; i < linenomax ; i++) {
+		if (curpos < lineno[i]) {
+			no = i;
+			break;
 		}
 	}
-	return (no + 1);
+	return (no);
 }
 
 
@@ -211,7 +246,8 @@
 	LineParsePtr = 0;
 
 	// current line number (2005.7.18 yutaka)
-	LineNo = getCurrentLineNumber(Buff[INest], BuffPtr[INest]); 
+	// \x83o\x83b\x83t\x83@\x82̃C\x83\x93\x83f\x83b\x83N\x83X\x82\xA9\x82獂\x91\xAC\x82ɍs\x94ԍ\x86\x82\xF0\x88\xF8\x82\xAF\x82\xE9\x82悤\x82ɂ\xB5\x82\xBD\x81B(2014.1.18 yutaka)
+	LineNo = getCurrentLineNumber(BuffPtr[INest], BuffLineNo[INest], BuffLineNoMaxIndex[INest]); 
 
 	while ((BuffPtr[INest]<BuffLen[INest]) &&
 		(b<0x20) && (b!=0x09))
@@ -339,6 +375,9 @@
 			GlobalFree(BuffHandle[i]);
 		}
 		BuffHandle[i] = NULL;
+
+		free(BuffLineNo[i]);
+		BuffLineNoMaxIndex[i] = 0;
 	}
 
 	while ((SP>0) && (LevelStack[SP-1]>=IBuff)) {



Ttssh2-commit メーリングリストの案内
Back to archive index