@@ -38,49 +38,14 @@ struct ScopedBuffer(T, size_t bytes = 4096)
3838 return  * cast (inout (T[_bufferLength])* )&_scopeBufferPayload;
3939 }
4040
41-  // /
42-  void  reserve (size_t  n) @trusted   scope 
41+  // / Reserve `n` extra more elements. 
42+  void  reserve (size_t  n) @safe   scope 
4343 {
44-  import  mir.internal.memory: realloc, malloc;
45-  const  nextLength = _currentLength +  n;
46-  if  (_buffer.length ==  0 )
47-  {
48-  if  (nextLength <=  _bufferLength)
49-  {
50-  return ;
51-  }
52-  else 
53-  {
54-  const  newLen = nextLength <<  1 ;
55-  if  (auto  p = malloc(T.sizeof *  newLen))
56-  {
57-  _buffer = (cast (T* )p)[0  ..  newLen];
58-  }
59-  else  assert (0 );
60-  version  (mir_secure_memory)
61-  {
62-  (cast (ubyte [])_buffer)[] = 0 ;
63-  }
64-  memcpy(cast (void * )_buffer.ptr, _scopeBuffer.ptr, T.sizeof *  (nextLength -  n));
65-  }
66-  }
67-  else 
68-  if  (nextLength >  _buffer.length)
69-  {
70-  const  newLen = nextLength <<  1 ;
71-  if  (auto  p = realloc(cast (void * )_buffer.ptr, T.sizeof *  newLen))
72-  {
73-  _buffer = (cast (T* )p)[0  ..  newLen];
74-  }
75-  else  assert (0 );
76-  version  (mir_secure_memory)
77-  {
78-  (cast (ubyte [])_buffer[nextLength ..  $])[] = 0 ;
79-  }
80-  }
44+  prepare(n);
45+  _currentLength -=  n;
8146 }
8247
83-  // /
48+  // / Return a slice to `n` more elements. 
8449 T[] prepare (size_t  n) @trusted  scope 
8550 {
8651 import  mir.internal.memory: realloc, malloc;
0 commit comments