if (!mustRealloc && len_ >= req.maxCapacity)
return spaceSize(); // but we cannot reallocate
- const size_type newSpace = std::min(req.idealSpace, maxSize - len_);
+ const size_type desiredSpace = std::max(req.minSpace, req.idealSpace);
+ const size_type newSpace = std::min(desiredSpace, maxSize - len_);
reserveCapacity(std::min(len_ + newSpace, req.maxCapacity));
debugs(24, 7, id << " now: " << off_ << '+' << len_ << '+' << spaceSize() <<
'=' << store_->capacity);
/*
* Parameters are listed in the reverse order of importance: Satisfaction of
* the lower-listed requirements may violate the higher-listed requirements.
+ * For example, idealSpace has no effect unless it exceeds minSpace.
*/
size_type idealSpace = 0; ///< if allocating anyway, provide this much space
- size_type minSpace = 0; ///< allocate if spaceSize() is smaller
+ size_type minSpace = 0; ///< allocate [at least this much] if spaceSize() is smaller
size_type maxCapacity = SBuf::maxSize; ///< do not allocate more than this
bool allowShared = true; ///< whether sharing our storage with others is OK
};
b.append('X');
}
}
+
+ // the minimal space requirement should overwrite idealSpace preferences
+ requirements.minSpace = 10;
+ for (const int delta: {-1,0,+1}) {
+ requirements.idealSpace = requirements.minSpace + delta;
+ SBuf buffer;
+ buffer.reserve(requirements);
+ CPPUNIT_ASSERT(buffer.spaceSize() >= requirements.minSpace);
+ }
}
void