@@ -378,8 +378,6 @@ size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t* data, size
378378 // temporary buffer to hold parameter name
379379 uint8_t buf[TEMPLATE_PARAM_NAME_LENGTH + 1 ];
380380 String paramName;
381- // cache position to insert remainder of template parameter value
382- std::vector<uint8_t >::iterator i = _cache.end ();
383381 // If closing placeholder is found:
384382 if (pTemplateEnd) {
385383 // prepare argument to callback
@@ -403,16 +401,14 @@ size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t* data, size
403401 // prepare argument to callback
404402 *pTemplateEnd = 0 ;
405403 paramName = String (reinterpret_cast <char *>(buf));
406- // Copy remaining read-ahead data into cache (when std::vector::insert returning iterator will be available, these 3 lines can be simplified into 1)
407- const size_t pos = _cache.size ();
408- _cache.insert (_cache.end (), pTemplateEnd + 1 , buf + (&data[len - 1 ] - pTemplateStart) + readFromCacheOrContent);
409- i = _cache.begin () + pos;
404+ // Copy remaining read-ahead data into cache
405+ _cache.insert (_cache.begin (), pTemplateEnd + 1 , buf + (&data[len - 1 ] - pTemplateStart) + readFromCacheOrContent);
410406 pTemplateEnd = &data[len - 1 ];
411407 }
412408 else // closing placeholder not found in file data, store found percent symbol as is and advance to the next position
413409 {
414410 // but first, store read file data in cache
415- _cache.insert (_cache.end (), buf + (&data[len - 1 ] - pTemplateStart), buf + (&data[len - 1 ] - pTemplateStart) + readFromCacheOrContent);
411+ _cache.insert (_cache.begin (), buf + (&data[len - 1 ] - pTemplateStart), buf + (&data[len - 1 ] - pTemplateStart) + readFromCacheOrContent);
416412 ++pTemplateStart;
417413 }
418414 }
@@ -434,9 +430,7 @@ size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t* data, size
434430 // make room for param value
435431 // 1. move extra data to cache if parameter value is longer than placeholder AND if there is no room to store
436432 if ((pTemplateEnd + 1 < pTemplateStart + numBytesCopied) && (originalLen - (pTemplateStart + numBytesCopied - pTemplateEnd - 1 ) < len)) {
437- size_t pos = i - _cache.begin ();
438- _cache.insert (i, &data[originalLen - (pTemplateStart + numBytesCopied - pTemplateEnd - 1 )], &data[len]);
439- i = _cache.begin () + pos;
433+ _cache.insert (_cache.begin (), &data[originalLen - (pTemplateStart + numBytesCopied - pTemplateEnd - 1 )], &data[len]);
440434 // 2. parameter value is longer than placeholder text, push the data after placeholder which not saved into cache further to the end
441435 memmove (pTemplateStart + numBytesCopied, pTemplateEnd + 1 , &data[originalLen] - pTemplateStart - numBytesCopied);
442436 } else if (pTemplateEnd + 1 != pTemplateStart + numBytesCopied)
@@ -447,7 +441,7 @@ size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t* data, size
447441 memcpy (pTemplateStart, pvstr, numBytesCopied);
448442 // If result is longer than buffer, copy the remainder into cache (this could happen only if placeholder text itself did not fit entirely in buffer)
449443 if (numBytesCopied < pvlen) {
450- _cache.insert (i , pvstr + numBytesCopied, pvstr + pvlen);
444+ _cache.insert (_cache. begin () , pvstr + numBytesCopied, pvstr + pvlen);
451445 } else if (pTemplateStart + numBytesCopied < pTemplateEnd + 1 ) { // result is copied fully; if result is shorter than placeholder text...
452446 // there is some free room, fill it from cache
453447 const size_t roomFreed = pTemplateEnd + 1 - pTemplateStart - numBytesCopied;
0 commit comments