@@ -26,6 +26,16 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
2626 throw new ArgumentException ( $ "Invalid member ID: { memberId } ") ;
2727 }
2828
29+ if ( targetChunkSize <= 0 )
30+ {
31+ throw new ArgumentException ( "targetChunkSize must be positive" , nameof ( targetChunkSize ) ) ;
32+ }
33+
34+ if ( overlap <= 0 )
35+ {
36+ throw new ArgumentException ( "overlap must be positive" , nameof ( overlap ) ) ;
37+ }
38+
2939 // Get the source document to analyze
3040 var document = decompilerService . DecompileMember ( memberId , includeHeader : true ) ;
3141 var totalLines = document . TotalLines ;
@@ -36,7 +46,7 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
3646 {
3747 result = new ChunkPlanResult (
3848 memberId ,
39- new List < ChunkInfo > ( ) ,
49+ Array . Empty < ChunkInfo > ( ) ,
4050 0 ,
4151 0 ,
4252 targetChunkSize ,
@@ -46,15 +56,11 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
4656 else
4757 {
4858 // Estimate average characters per line based on the document
49- var divisor = Math . Min ( totalLines , 10 ) ;
59+ var divisor = Math . Max ( 1 , Math . Min ( totalLines , 10 ) ) ;
5060 int avgCharsPerLine ;
5161 try
5262 {
5363 var sampleSlice = decompilerService . GetSourceSlice ( memberId , 1 , divisor ) ;
54- if ( divisor == 0 )
55- {
56- divisor = 1 ;
57- }
5864 avgCharsPerLine = sampleSlice . Code . Length / divisor ;
5965 }
6066 catch
@@ -70,10 +76,10 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
7076 // Calculate target lines per chunk
7177 var targetLinesPerChunk = Math . Max ( 1 , targetChunkSize / avgCharsPerLine ) ;
7278
73- if ( overlap >= targetLinesPerChunk || overlap < 0 )
79+ if ( overlap >= targetLinesPerChunk )
7480 {
7581 throw new ArgumentException (
76- $ "Overlap must be between 0 and { targetLinesPerChunk - 1 } ",
82+ $ "Overlap must be less than { targetLinesPerChunk } ",
7783 nameof ( overlap ) ) ;
7884 }
7985
@@ -101,7 +107,7 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
101107
102108 result = new ChunkPlanResult (
103109 memberId ,
104- chunks ,
110+ chunks . ToArray ( ) ,
105111 totalLines ,
106112 totalLines * avgCharsPerLine ,
107113 targetChunkSize ,
@@ -118,7 +124,7 @@ internal record ChunkInfo(int StartLine, int EndLine, int EstimatedChars);
118124
119125internal record ChunkPlanResult (
120126 string MemberId ,
121- List < ChunkInfo > Chunks ,
127+ ChunkInfo [ ] Chunks ,
122128 int TotalLines ,
123129 int EstimatedChars ,
124130 int TargetChunkSize ,
0 commit comments