From 09df47d0f262800443ea4a9a506a1ce299431ae5 Mon Sep 17 00:00:00 2001 From: kichik Date: Thu, 8 May 2008 10:27:32 +0000 Subject: [PATCH] mutable instead of const_cast for nicer code git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5636 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/mmap.cpp | 14 ++++++-------- Source/mmap.h | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/mmap.cpp b/Source/mmap.cpp index 938f6a50..e6f21f39 100644 --- a/Source/mmap.cpp +++ b/Source/mmap.cpp @@ -263,12 +263,10 @@ void *MMapFile::get(int offset, int *sizep) const size += offset - alignedoffset; #ifdef _WIN32 - const_cast(this)->m_pView = - MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size); + m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size); #else - const_cast(this)->m_pView = - mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset); - const_cast(this)->m_iMappedSize = *sizep = size; + m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset); + m_iMappedSize = *sizep = size; #endif #ifdef _WIN32 @@ -297,11 +295,11 @@ void *MMapFile::getmore(int offset, int size) const #ifndef _WIN32 int iMappedSizeBackup = m_iMappedSize; #endif - const_cast(this)->m_pView = 0; + m_pView = 0; pView = get(offset, size); - const_cast(this)->m_pView = pViewBackup; + m_pView = pViewBackup; #ifndef _WIN32 - const_cast(this)->m_iMappedSize = iMappedSizeBackup; + m_iMappedSize = iMappedSizeBackup; #endif return pView; } diff --git a/Source/mmap.h b/Source/mmap.h index 5b7286a4..c1c6627c 100644 --- a/Source/mmap.h +++ b/Source/mmap.h @@ -74,8 +74,8 @@ class MMapFile : public IMMap int m_hFileDesc; int m_iMappedSize; #endif - void *m_pView; - int m_iSize; + mutable void *m_pView; + mutable int m_iSize; BOOL m_bReadOnly; BOOL m_bTempHandle;