QFsFileEngine: avoid triple(quadruple) lookup of the same key
Instead of contains(), 1-2x operator[](), and remove(), equalling 3-4 separate lookups, use find() + erase(), which does just one lookup. Since our erase() function is C++11-compliant these days and takes const_iterator instead of (mutable) iterator, we can use the const find() overload to delay a detach (attempt) until we actually erase(). Change-Id: I8e67a48e221e548528049fa093ab7ef2f1802f7e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
a46d0b480b
commit
e933d71a61
@ -646,18 +646,19 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr)
|
||||
{
|
||||
#if !defined(Q_OS_INTEGRITY)
|
||||
Q_Q(QFSFileEngine);
|
||||
if (!maps.contains(ptr)) {
|
||||
const auto it = std::as_const(maps).find(ptr);
|
||||
if (it == maps.cend()) {
|
||||
q->setError(QFile::PermissionsError, qt_error_string(EACCES));
|
||||
return false;
|
||||
}
|
||||
|
||||
uchar *start = ptr - maps[ptr].first;
|
||||
size_t len = maps[ptr].second;
|
||||
uchar *start = ptr - it->first;
|
||||
size_t len = it->second;
|
||||
if (-1 == munmap(start, len)) {
|
||||
q->setError(QFile::UnspecifiedError, qt_error_string(errno));
|
||||
return false;
|
||||
}
|
||||
maps.remove(ptr);
|
||||
maps.erase(it);
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
@ -871,17 +871,18 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
|
||||
bool QFSFileEnginePrivate::unmap(uchar *ptr)
|
||||
{
|
||||
Q_Q(QFSFileEngine);
|
||||
if (!maps.contains(ptr)) {
|
||||
const auto it = std::as_const(maps).find(ptr);
|
||||
if (it == maps.cend()) {
|
||||
q->setError(QFile::PermissionsError, qt_error_string(ERROR_ACCESS_DENIED));
|
||||
return false;
|
||||
}
|
||||
uchar *start = ptr - maps[ptr];
|
||||
uchar *start = ptr - *it;
|
||||
if (!UnmapViewOfFile(start)) {
|
||||
q->setError(QFile::PermissionsError, qt_error_string());
|
||||
return false;
|
||||
}
|
||||
|
||||
maps.remove(ptr);
|
||||
maps.erase(it);
|
||||
if (maps.isEmpty()) {
|
||||
::CloseHandle(mapHandle);
|
||||
mapHandle = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user