used existing empty place in vector when allocate a new one

This commit is contained in:
georgemoralis 2023-11-06 19:09:00 +02:00
parent bfbe67bc42
commit 55a2bfcc29
1 changed files with 8 additions and 1 deletions

View File

@ -40,7 +40,14 @@ int HandleTable::createHandle() {
file->isOpened = false; file->isOpened = false;
int existingFilesNum = m_files.size(); int existingFilesNum = m_files.size();
// TODO when i close a file m_files probably have a open pos , so we can fill this
for (int index = 0; index < existingFilesNum; index++) {
if (m_files.at(index) == nullptr) {
m_files[index] = file;
return index;
}
}
m_files.push_back(file); m_files.push_back(file);
return existingFilesNum - 1; return existingFilesNum - 1;