@@ -268,26 +268,23 @@ public void ReducingCapacity(in nuint reducingCount)
268268 _stackMemoryC = newMemory;
269269 _start = _stackMemoryC.Start;{ incrementVersion }
270270 }}
271- else
271+ else if(_stackMemoryS != null)
272272 {{
273- if( _stackMemoryS != null )
273+ if (new IntPtr( _stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )) )
274274 {{
275- if (new IntPtr(_stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
276- {{
277- throw new Exception(""Failed to reduce available memory, stack moved further"");
278- }}
279-
280- _stackMemoryS->FreeMemory(reducingCount * { sizeOfStr } );
275+ throw new Exception(""Failed to reduce available memory, stack moved further"");
281276 }}
282- else if (_stackMemoryC != null)
283- {{
284- if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
285- {{
286- throw new Exception(""Failed to reduce available memory, stack moved further"");
287- }}
288277
289- _stackMemoryC.FreeMemory(reducingCount * { sizeOfStr } );
278+ _stackMemoryS->FreeMemory(reducingCount * { sizeOfStr } );
279+ }}
280+ else if (_stackMemoryC != null)
281+ {{
282+ if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
283+ {{
284+ throw new Exception(""Failed to reduce available memory, stack moved further"");
290285 }}
286+
287+ _stackMemoryC.FreeMemory(reducingCount * { sizeOfStr } );
291288 }}
292289
293290 Capacity -= reducingCount;
@@ -325,26 +322,23 @@ public void ExpandCapacity(in nuint expandCount)
325322 _stackMemoryC = newMemory;
326323 _start = _stackMemoryC.Start;{ incrementVersion }
327324 }}
328- else
325+ else if(_stackMemoryS != null)
329326 {{
330- if( _stackMemoryS != null )
327+ if (new IntPtr( _stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )) )
331328 {{
332- if (new IntPtr(_stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
333- {{
334- throw new Exception(""Failed to expand available memory, stack moved further"");
335- }}
336-
337- _stackMemoryS->AllocateMemory(expandCount * { sizeOfStr } );
329+ throw new Exception(""Failed to expand available memory, stack moved further"");
338330 }}
339- else if (_stackMemoryC != null)
340- {{
341- if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
342- {{
343- throw new Exception(""Failed to expand available memory, stack moved further"");
344- }}
345331
346- _stackMemoryC.AllocateMemory(expandCount * { sizeOfStr } );
332+ _stackMemoryS->AllocateMemory(expandCount * { sizeOfStr } );
333+ }}
334+ else if (_stackMemoryC != null)
335+ {{
336+ if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
337+ {{
338+ throw new Exception(""Failed to expand available memory, stack moved further"");
347339 }}
340+
341+ _stackMemoryC.AllocateMemory(expandCount * { sizeOfStr } );
348342 }}
349343
350344 Capacity += expandCount;
@@ -382,31 +376,28 @@ public bool TryExpandCapacity(in nuint expandCount)
382376 _stackMemoryC = newMemory;
383377 _start = _stackMemoryC.Start;{ incrementVersion }
384378 }}
385- else
379+ else if(_stackMemoryS != null)
386380 {{
387- if( _stackMemoryS != null )
381+ if (new IntPtr( _stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )) )
388382 {{
389- if (new IntPtr(_stackMemoryS->Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
390- {{
391- return false;
392- }}
383+ return false;
384+ }}
393385
394- if(!_stackMemoryS->TryAllocateMemory(expandCount * { sizeOfStr } , out _))
395- {{
396- return false;
397- }}
386+ if(!_stackMemoryS->TryAllocateMemory(expandCount * { sizeOfStr } , out _))
387+ {{
388+ return false;
398389 }}
399- else if (_stackMemoryC != null)
390+ }}
391+ else if (_stackMemoryC != null)
392+ {{
393+ if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
400394 {{
401- if (new IntPtr(_stackMemoryC.Current) != new IntPtr((byte*)_start + (Capacity * { sizeOfStr } )))
402- {{
403- throw new Exception(""Failed to expand available memory, stack moved further"");
404- }}
395+ throw new Exception(""Failed to expand available memory, stack moved further"");
396+ }}
405397
406- if(!_stackMemoryC.TryAllocateMemory(expandCount * { sizeOfStr } , out _))
407- {{
408- return false;
409- }}
398+ if(!_stackMemoryC.TryAllocateMemory(expandCount * { sizeOfStr } , out _))
399+ {{
400+ return false;
410401 }}
411402 }}
412403
0 commit comments