同じ文字列の最適化パッチ
これは2008年2月7日19時48分現在公開されているOpenHSP ver.3.2beta1 に対するパッチです。
OpenHSP ver.3.2beta1 のライセンスは以下の通りです。
OpenHSP Copyright (C) 1997-2008, Onion Software/onitama, all rights reserved. This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed.
diff -Naru hspcmp.orig/codegen.cpp hspcmp/codegen.cpp --- hspcmp.orig/codegen.cpp Mon Jan 14 09:30:26 2008 +++ hspcmp/codegen.cpp Thu Feb 07 20:26:35 2008 @@ -2429,9 +2429,22 @@ // Register strings to data segment // int i; + if( hed_cmpmode & CMPMODE_OPTCODE ) { + // 同じ文字列の最適化 + int *buffer = (int *)(ds_opt_idx->GetBuffer()); + int size = ds_opt_idx->GetSize() / sizeof( int ); + for( int i = 0; i < size; i ++ ) { + int offset = buffer[i]; + if( strcmp( ds_buf->GetBuffer() + offset, str ) == 0 ) { + if ( hed_cmpmode & CMPMODE_OPTINFO ) Mesf( "#Optimisation string [%s]", str ); + return offset; + } + } + } i = ds_buf->GetSize(); ds_buf->PutStr( str ); ds_buf->Put( (char)0 );; + if( hed_cmpmode & CMPMODE_OPTCODE ) ds_opt_idx->Put( i ); return i; } @@ -2777,6 +2790,7 @@ mi_buf = new CMemBuf; fi2_buf = new CMemBuf; hpi_buf = new CMemBuf; + ds_opt_idx = new CMemBuf; bakbuf.PutStr( srcbuf->GetBuffer() ); // プリプロセッサソースを保存する @@ -2912,6 +2926,7 @@ } } + delete ds_opt_idx; delete hpi_buf; delete fi2_buf; delete mi_buf; diff -Naru hspcmp.orig/token.h hspcmp/token.h --- hspcmp.orig/token.h Mon Jan 14 09:30:26 2008 +++ hspcmp/token.h Thu Feb 07 19:04:21 2008 @@ -385,6 +385,7 @@ CMemBuf *mi_buf; CMemBuf *fi2_buf; CMemBuf *hpi_buf; + CMemBuf *ds_opt_idx; // for Header info int hed_option;