OSDN Git Service

* WorkBackup: 2015/04/29(Wed) AM 03:30
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Tue, 28 Apr 2015 18:30:48 +0000 (03:30 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Tue, 28 Apr 2015 18:30:48 +0000 (03:30 +0900)
libedittext/drd64_libedittext_config.h
libedittext/drd64_libedittext_file.c
libedittext/drd64_libedittext_section.c

index 0d2e95c..7c3e437 100644 (file)
@@ -55,6 +55,8 @@ Comment:
 #define DRD64_LIBEDITTEXT_DEFAULT_LINESORT_STEP2SCALE          5
 
 #define        DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS                         512
+#define        DRD64_LIBEDITTEXT_DEFAULT_REMAIN_SECPOWS                        22
+       /* This value is 32 - log2(DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS) - 1 */
 #define        DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS                          64
 #define        DRD64_LIBEDITTEXT_DEFAULT_SECTIONSTEPS                          16
 
index aa8df83..75c5ca1 100644 (file)
@@ -278,6 +278,9 @@ int
        i_result        = LibEditText_Line_AddSortChain( p_tinfo, p_line );     
        if( 0x00 != i_result )  { return -0x02; }
 
+       i_result        = LibEditText_Section_ConstractSection( p_tinfo );
+       if( 0x00 != i_result )  { puts("error");return -0x03; }
+       
        return p_tinfo->i_id;
 }
 
index a545737..b61d066 100644 (file)
@@ -71,6 +71,7 @@ int
 {
        DWord   dw_cnt;
        DWord   dw_line;
+       DWord   dw_sections;
        LibEditText_LineSection         *p_section;
        LibEditText_LineSection         *p_nowsec;
        LibEditText_LineInfo            *p_line;
@@ -83,10 +84,8 @@ int
                dw_line         = (p_tinfo->dw_maxline * dw_cnt) / p_tinfo->dw_sections;
                p_nowsec        = (p_section + dw_cnt);
                
-               if( INVALID_LINE != p_nowsec->dw_linfoid )      {
-                       p_nowsec->dw_linfoid    = INVALID_LINE - 1;
-                       p_nowsec->dw_line               = dw_line;
-               }
+               p_nowsec->dw_linfoid    = INVALID_LINE - 1;
+               p_nowsec->dw_line               = dw_line;
        }
 
        p_line  = LINFO(p_tinfo, p_tinfo->dw_line_start);
@@ -95,14 +94,19 @@ int
        }
 
        p_nowsec        = p_section;
+       dw_sections     = p_tinfo->dw_sections;
        for( dw_line = 0; dw_line < p_tinfo->dw_maxline; dw_line++ )    {
                while( dw_line == p_nowsec->dw_line )   {
                        p_nowsec->dw_linfoid    = p_line->dw_id; 
                        p_nowsec++;
+                       if( 0 == --dw_sections)
+                               { goto goto_LibEditText_Section_ConstractSection_post; }
                }
                p_line  = LINFO(p_tinfo, p_line->dw_next);
        }
 
+goto_LibEditText_Section_ConstractSection_post:
+
        return 0x00;
 }
 
@@ -137,33 +141,57 @@ int
        LibEditText_Section_InitSection(
                        LibEditText_TextInfo    *p_tinfo )
 {
+       int             i_tmp;
        int             i_result        = 0x00;
-       DWord   dw_cnt;
+       DWord           dw_cnt;
+       DWord           dw_req_sections;
+       DWord           dw_allocsections;
+       DWord           dw_stepsection;
        LibEditText_LineSection         *p_section;
        LibEditText_LineSection         *p_nowsec;
 
        assert( NULL != p_tinfo );
 
+       p_tinfo->dw_bufsections = DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS;
+       p_tinfo->dw_sections    = DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS;
+       p_tinfo->dw_sect_steps  = DRD64_LIBEDITTEXT_DEFAULT_SECTIONSTEPS;
+
+       dw_req_sections = p_tinfo->dw_maxline / DRD64_LIBEDITTEXT_DEFAULT_SECTIONSTEPS;
+
+       if( DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS < dw_req_sections ) {
+               dw_allocsections        = DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS * 2;
+               dw_stepsection          = DRD64_LIBEDITTEXT_DEFAULT_SECTIONSTEPS * 2;
+               for( i_tmp = 0; i_tmp < DRD64_LIBEDITTEXT_DEFAULT_REMAIN_SECPOWS; i_tmp++ )     {
+                       if( dw_req_sections < dw_allocsections )        { break; }
+                       dw_allocsections        *= 2;
+                       dw_stepsection          *= 2;
+               }
+               if( DRD64_LIBEDITTEXT_DEFAULT_REMAIN_SECPOWS == i_tmp ) { return -0x01; }
+
+               p_tinfo->dw_bufsections = dw_allocsections;
+               p_tinfo->dw_sections    = dw_req_sections;
+               p_tinfo->dw_sect_steps  = dw_stepsection;
+       }
+       else if( DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS < dw_req_sections )             {
+               p_tinfo->dw_sections    = dw_req_sections;
+       }
+
        p_section       = (LibEditText_LineSection *)malloc(
                                                sizeof( LibEditText_LineSection )
-                                                       * DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS );
+                                                       * p_tinfo->dw_bufsections );
        if( NULL == p_section )         {
                return -0x01;
        }
        memset( p_section, 0x00, sizeof( LibEditText_LineSection )
-                                                       * DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS );
+                                                       * p_tinfo->dw_bufsections );
 
        p_nowsec        = p_section;
-       for( dw_cnt = 0; dw_cnt < DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS; dw_cnt++ )    {
+       for( dw_cnt = 0; dw_cnt < p_tinfo->dw_bufsections; dw_cnt++ )   {
                p_nowsec->dw_line               = 0;
                p_nowsec->dw_linfoid    = INVALID_LINE;
        }
 
        p_tinfo->p_section              = p_section;
-       p_tinfo->dw_bufsections = DRD64_LIBEDITTEXT_DEFAULT_ALLOCSECTIONS
-                                                               - DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS;
-       p_tinfo->dw_sections    = DRD64_LIBEDITTEXT_DEFAULT_LINESECTIONS;
-       p_tinfo->dw_sect_steps  = DRD64_LIBEDITTEXT_DEFAULT_SECTIONSTEPS;
 
        return i_result;
 }