diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2017-01-07 19:22:48 -0500 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2017-01-08 01:01:48 +0000 |
commit | 7c117c508c1eaa5c930481fb82c21fee6d71af0c (patch) | |
tree | bac06353bc03998d4d3da06566b0d35880d13230 /package | |
parent | 63ddc8dc4ae1f3c3ee2f860c34886688b0ed2d57 (diff) |
Clean up and annotate the code a bit.
Change-Id: I5f0c6130e5cf21f93bb1309f7bf148bd40b3821d
Reviewed-on: https://gerrit.libreoffice.org/32827
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
Diffstat (limited to 'package')
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 3c6eb4848894..c550321f0012 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -777,49 +777,62 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) throw( NoSuchElementException, RuntimeException, std::exception ) { OUString sTemp, sDirName; - sal_Int32 nOldIndex, nIndex, nStreamIndex; + sal_Int32 nOldIndex, nStreamIndex; FolderHash::iterator aIter; - if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + sal_Int32 nIndex = aName.getLength(); + + if (aName == "/") + // root directory. return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) ); nStreamIndex = aName.lastIndexOf ( '/' ); - bool bFolder = nStreamIndex == nIndex-1; + bool bFolder = nStreamIndex == nIndex-1; // last character is '/'. + if ( nStreamIndex != -1 ) { + // The name contains '/'. sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { + // There is a cached entry for this name. + + ZipPackageFolder* pFolder = aIter->second; + if ( bFolder ) { + // Determine the directory name. sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == ( *aIter ).second->getName() ) - return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) ); - m_aRecent.erase ( aIter ); + if (sTemp == pFolder->getName()) + return makeAny(uno::Reference<XUnoTunnel>(pFolder)); } else { + // Determine the file name. sTemp = aName.copy ( nStreamIndex + 1 ); - if ( ( *aIter ).second->hasByName( sTemp ) ) - return ( *aIter ).second->getByName( sTemp ); - m_aRecent.erase( aIter ); + if (pFolder->hasByName(sTemp)) + return pFolder->getByName(sTemp); } + + m_aRecent.erase( aIter ); } } - else - { - if ( m_pRootFolder->hasByName ( aName ) ) - return m_pRootFolder->getByName ( aName ); - } + else if ( m_pRootFolder->hasByName ( aName ) ) + // top-level element. + return m_pRootFolder->getByName ( aName ); + + // Not in the cache. Search normally. nOldIndex = 0; ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = nullptr; + // Find the right directory for the given path. + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); @@ -838,7 +851,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( bFolder ) { if ( nStreamIndex != -1 ) - m_aRecent[sDirName] = pPrevious; + m_aRecent[sDirName] = pPrevious; // cache it. return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); } @@ -847,7 +860,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) if ( pCurrent->hasByName ( sTemp ) ) { if ( nStreamIndex != -1 ) - m_aRecent[sDirName] = pCurrent; + m_aRecent[sDirName] = pCurrent; // cache it. return pCurrent->getByName( sTemp ); } @@ -858,10 +871,13 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) throw( RuntimeException, std::exception ) { OUString sTemp, sDirName; - sal_Int32 nOldIndex, nIndex, nStreamIndex; + sal_Int32 nOldIndex, nStreamIndex; FolderHash::iterator aIter; - if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + sal_Int32 nIndex = aName.getLength(); + + if (aName == "/") + // root directory return true; try |