[Libreoffice-commits] core.git: 3 commits - framework/source sw/source
Takeshi Abe
tabe at fixedpoint.jp
Thu Apr 17 05:00:16 PDT 2014
framework/source/uielement/imagebuttontoolbarcontroller.cxx | 4
sw/source/filter/ww8/hash_wrap.hxx | 111 ------------
sw/source/filter/ww8/ww8par.cxx | 1
sw/source/filter/ww8/ww8scan.cxx | 81 +++-----
sw/source/filter/ww8/ww8scan.hxx | 27 ++
5 files changed, 62 insertions(+), 162 deletions(-)
New commits:
commit 2a3e221c8807789afcbbe9ea5eae3c3fc90a473c
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Wed Apr 16 00:22:16 2014 +0900
Fix a memory leak
The stream should be freed eventually in any case.
Change-Id: I5432b48de5641adc7a13a852fea49adc18bf963b
Reviewed-on: https://gerrit.libreoffice.org/9016
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/framework/source/uielement/imagebuttontoolbarcontroller.cxx b/framework/source/uielement/imagebuttontoolbarcontroller.cxx
index 733b322..7c385f2 100644
--- a/framework/source/uielement/imagebuttontoolbarcontroller.cxx
+++ b/framework/source/uielement/imagebuttontoolbarcontroller.cxx
@@ -40,6 +40,7 @@
#include <vcl/graphicfilter.hxx>
#include <vcl/toolbox.hxx>
#include <svtools/miscopt.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::awt;
@@ -159,7 +160,7 @@ void ImageButtonToolbarController::executeControlCommand( const ::com::sun::star
bool ImageButtonToolbarController::ReadImageFromURL( bool bBigImage, const OUString& aImageURL, Image& aImage )
{
- SvStream* pStream = utl::UcbStreamHelper::CreateStream( aImageURL, STREAM_STD_READ );
+ boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aImageURL, STREAM_STD_READ ));
if ( pStream && ( pStream->GetErrorCode() == 0 ))
{
// Use graphic class to also support more graphic formats (bmp,png,...)
@@ -183,7 +184,6 @@ bool ImageButtonToolbarController::ReadImageFromURL( bool bBigImage, const OUStr
}
}
- delete pStream;
return false;
}
commit a0656ed3386a071ee43440ee870a90d7a1fe7fa7
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 17 12:09:50 2014 +0200
Simplify wwSprmSearcher
Change-Id: I1642556f507af9db722dadda707ae11b4080fcf0
diff --git a/sw/source/filter/ww8/hash_wrap.hxx b/sw/source/filter/ww8/hash_wrap.hxx
deleted file mode 100644
index a07dd66..0000000
--- a/sw/source/filter/ww8/hash_wrap.hxx
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-//this is a shameless rip from sortedarray.hxx but changed to boost::unordered_set
-
-#ifndef INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX
-#define INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX
-
-#include <boost/unordered_set.hpp>
-
-//simple wrapper around boost::unordered_set to behave like sorted array
-namespace ww
-{
- /** simple template that manages a hash
-
- @author
- <a href="mailto:mikeleib at openoffice.org">Michael Leibowitz</a>
- */
- template<class C, class HashFcn = boost::hash<C> > class WrappedHash
- {
- private:
- boost::unordered_set<C, HashFcn> mHashSet;
-
- //No copying
- WrappedHash(const WrappedHash&);
- WrappedHash& operator=(const WrappedHash&);
- public:
- //Find an entry, return its address if found and 0 if not
- const C* search(C aSrch) const
- {
- typename boost::unordered_set<C, HashFcn>::const_iterator it;
- it= mHashSet.find(aSrch);
- if (it != mHashSet.end())
- return &(*it);
- else
- return 0;
- }
-
- WrappedHash(const C *pWwSprmTab, const size_t nNoElems)
- {
- OSL_ENSURE(nNoElems && pWwSprmTab, "WW8: empty Array: Don't do that");
- const C *pIter = pWwSprmTab;
- const C *pEnd = pWwSprmTab + nNoElems;
- while (pIter < pEnd)
- {
- mHashSet.insert(*pIter);
- pIter++;
- }
-#if OSL_DEBUG_LEVEL > 1
- bool bBroken=false;
- OUString sError;
- pIter = pWwSprmTab;
- const C *pBeforeEnd = pWwSprmTab + nNoElems - 1;
- while (pIter < pBeforeEnd)
- {
- if (*pIter == *(pIter+1))
- {
- if (!bBroken)
- {
- sError =
- "WW8: Duplicate in list, almost certainly don't "
- "want that!\n"
- "(You will not see this message again unless you "
- "restart)\n"
- "Extra entries are...\n";
- bBroken=true;
- }
-
- size_t nSize = sizeof(C);
- const sal_uInt8 *pHack =
- reinterpret_cast<const sal_uInt8 *>(&(*pIter));
- for (size_t i=0; i < nSize; ++i)
- {
- sError += OUString::number(
- static_cast<sal_Int32>(pHack[i]), 16);
- sError += OUString(' ');
- }
- sError += OUString('\n');
- while (*pIter == *(pIter+1) && pIter < pBeforeEnd)
- ++pIter;
- }
- else
- ++pIter;
- }
- if (bBroken)
- {
- OSL_FAIL( OUStringToOString( sError, RTL_TEXTENCODING_ASCII_US ).getStr() );
- }
-#endif
- }
- };
-}
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index ba99b4f..8f4927d 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <boost/noncopyable.hpp>
+#include <boost/unordered_set.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <i18nlangtag/languagetag.hxx>
diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index f271194..cfa95f0 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -105,11 +105,6 @@ namespace
}
}
-inline bool operator==(const SprmInfo &rFirst, const SprmInfo &rSecond)
-{
- return (rFirst.nId == rSecond.nId);
-}
-
const wwSprmSearcher *wwSprmParser::GetWW2SprmSearcher()
{
//double lock me
@@ -800,53 +795,47 @@ wwSprmParser::wwSprmParser(ww::WordVersion eVersion) : meVersion(eVersion)
SprmInfo wwSprmParser::GetSprmInfo(sal_uInt16 nId) const
{
- // Find sprm
- SprmInfo aSrch={0,0,0};
- aSrch.nId = nId;
- const SprmInfo* pFound = mpKnownSprms->search(aSrch);
- if (pFound == 0)
+ const SprmInfo* pFound = mpKnownSprms->search(nId);
+ if (pFound != 0)
{
- OSL_ENSURE(ww::IsEightPlus(meVersion),
- "Unknown ww7- sprm, dangerous, report to development");
+ return *pFound;
+ }
- aSrch.nId = 0;
- aSrch.nLen = 0;
- //All the unknown ww7 sprms appear to be variable (which makes sense)
- aSrch.nVari = L_VAR;
+ OSL_ENSURE(ww::IsEightPlus(meVersion),
+ "Unknown ww7- sprm, dangerous, report to development");
- if (ww::IsEightPlus(meVersion)) //We can recover perfectly in this case
+ //All the unknown ww7 sprms appear to be variable (which makes sense)
+ SprmInfo aSrch = { nId, 0, L_VAR };
+ if (ww::IsEightPlus(meVersion)) //We can recover perfectly in this case
+ {
+ aSrch.nVari = L_FIX;
+ switch (nId >> 13)
{
- aSrch.nVari = L_FIX;
- switch (nId >> 13)
- {
- case 0:
- case 1:
- aSrch.nLen = 1;
- break;
- case 2:
- aSrch.nLen = 2;
- break;
- case 3:
- aSrch.nLen = 4;
- break;
- case 4:
- case 5:
- aSrch.nLen = 2;
- break;
- case 6:
- aSrch.nLen = 0;
- aSrch.nVari = L_VAR;
- break;
- case 7:
- default:
- aSrch.nLen = 3;
- break;
- }
+ case 0:
+ case 1:
+ aSrch.nLen = 1;
+ break;
+ case 2:
+ aSrch.nLen = 2;
+ break;
+ case 3:
+ aSrch.nLen = 4;
+ break;
+ case 4:
+ case 5:
+ aSrch.nLen = 2;
+ break;
+ case 6:
+ aSrch.nLen = 0;
+ aSrch.nVari = L_VAR;
+ break;
+ case 7:
+ default:
+ aSrch.nLen = 3;
+ break;
}
-
- pFound = &aSrch;
}
- return *pFound;
+ return aSrch;
}
//-end
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 9538447..5eb2ebe 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -23,14 +23,17 @@
#ifndef LONG_MAX
#include <limits.h>
#endif
+#include <cassert>
+#include <cstddef>
#include <stack>
#include <vector>
#include <list>
#include <algorithm>
+
+#include <boost/unordered_map.hpp>
#include <tools/solar.h>
#include <tools/stream.hxx>
#include <rtl/ustring.hxx>
-#include "hash_wrap.hxx"
#include "sortedarray.hxx"
#include "ww8struc.hxx"
@@ -70,7 +73,26 @@ struct SprmInfoHash
}
};
-typedef ww::WrappedHash<SprmInfo, SprmInfoHash> wwSprmSearcher;
+class wwSprmSearcher {
+public:
+ wwSprmSearcher(SprmInfo const * infos, std::size_t size) {
+ for (std::size_t i = 0; i != size; ++i) {
+ bool ins = map_.insert(Map::value_type(infos[i].nId, infos[i]))
+ .second;
+ assert(ins); (void) ins;
+ }
+ }
+
+ SprmInfo const * search(sal_uInt16 id) const {
+ Map::const_iterator i(map_.find(id));
+ return i == map_.end() ? 0 : &i->second;
+ }
+
+private:
+ typedef boost::unordered_map<sal_uInt16, SprmInfo> Map;
+
+ Map map_;
+};
/**
wwSprmParser knows how to take a sequence of bytes and split it up into
commit 892ba2c5bafb237f150598cc35f9776dffbdca69
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 17 11:48:46 2014 +0200
Remove unused typedef
Change-Id: I89c4a2a49af3e8af19e751a0f34bbaa8f4a3ee61
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 2faf883..9538447 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -71,7 +71,6 @@ struct SprmInfoHash
};
typedef ww::WrappedHash<SprmInfo, SprmInfoHash> wwSprmSearcher;
-typedef ww::WrappedHash<sal_uInt16> wwSprmSequence;
/**
wwSprmParser knows how to take a sequence of bytes and split it up into
More information about the Libreoffice-commits
mailing list