Permalink
Browse files

Don't write LayerMap if file has not been modified since begining (op…

…en).
  • Loading branch information...
1 parent 054573c commit 37419d85b3ddec08dd1973e22a63454b8abb246c @tex committed Nov 27, 2008
Showing with 18 additions and 2 deletions.
  1. +0 −1 TODO
  2. +6 −0 src/Compress.cpp
  3. +6 −0 src/LayerMap.cpp
  4. +6 −1 src/LayerMap.hpp
View
1 TODO
@@ -1 +0,0 @@
-Don't write index when file opened read-only.
View
6 src/Compress.cpp
@@ -577,6 +577,12 @@ void Compress::storeLayerMap()
{
rDebug("%s: m_fd: %d", __PRETTY_FUNCTION__, m_fd);
+ // Don't store LayerMap if it has not been modified
+ // since begining (open).
+
+ if (!m_lm.isModified())
+ return;
+
io::nonclosable_file_descriptor file(m_fd);
file.seek(m_RawFileSize, ios_base::beg);
View
6 src/LayerMap.cpp
@@ -15,6 +15,7 @@ std::ostream &operator<<(std::ostream &os, const LayerMap &rLm)
os << std::hex;
os << "-- m_MaxLevel: 0x" << rLm.m_MaxLevel <<
", m_MaxLength: 0x" << rLm.m_MaxLength <<
+ ", m_IsModified: " << rLm.m_IsModified <<
" -------" << std::endl;
for (LayerMap::con_t::const_iterator it = rLm.m_Map.begin(); it != rLm.m_Map.end(); ++it)
@@ -42,6 +43,8 @@ void LayerMap::Put(Block *pBl, bool bKeepLevel)
if (m_MaxLength < pBl->length)
m_MaxLength = pBl->length;
+ m_IsModified = true;
+
// cout << "State after Put: " << endl << *this << endl;
}
@@ -67,6 +70,9 @@ void LayerMap::Truncate(off_t offset)
}
++it;
}
+
+ m_IsModified = true;
+
// std::cout << "State after Truncate: " << std::endl << *this << std::endl;
}
View
7 src/LayerMap.hpp
@@ -38,6 +38,7 @@ class LayerMap
con_t m_Map;
unsigned int m_MaxLevel;
unsigned int m_MaxLength;
+ bool m_IsModified;
void next(off_t offset, con_t::const_iterator &it) const;
unsigned int length(con_t::const_iterator &it, off_t offset) const;
@@ -55,7 +56,8 @@ class LayerMap
public:
LayerMap() :
m_MaxLevel(1),
- m_MaxLength(0)
+ m_MaxLength(0),
+ m_IsModified(false)
{}
~LayerMap()
{
@@ -65,6 +67,7 @@ class LayerMap
{
m_MaxLevel = src.m_MaxLevel;
m_MaxLength = src.m_MaxLength;
+ m_IsModified = src.m_IsModified;
for (con_t::iterator it = m_Map.begin(); it != m_Map.end(); ++it)
delete(*it);
@@ -106,6 +109,8 @@ class LayerMap
return true;
}
+ bool isModified() const { return m_IsModified; }
+
friend std::ostream &operator<<(std::ostream &os, const LayerMap &rLm);
};

0 comments on commit 37419d8

Please sign in to comment.