Kaydet (Commit) 878439cc authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Move this string pool code to svl.

Change-Id: I1379fbc377607be8831133d64db2e14f8c75bff8
üst 6cea7618
/* -*- 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/.
*/
#ifndef SVL_STRINGPOOL_HXX
#define SVL_STRINGPOOL_HXX
#include "svl/svldllapi.h"
#include "rtl/ustring.hxx"
#include <boost/unordered_set.hpp>
namespace svl {
class SVL_DLLPUBLIC StringPool
{
typedef boost::unordered_set<OUString, OUStringHash> StrHashType;
StrHashType maStrPool;
public:
StringPool();
rtl_uString* intern( const OUString& rStr );
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -14,6 +14,8 @@
#include "types.hxx"
#include "platforminfo.hxx"
#include "svl/stringpool.hxx"
#include <vector>
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
......@@ -26,17 +28,14 @@ namespace sc {
struct FormulaGroupContext : boost::noncopyable
{
typedef boost::unordered_set<OUString, OUStringHash> StrHashType;
typedef std::vector<double> NumArrayType;
typedef std::vector<rtl_uString*> StrArrayType;
typedef boost::ptr_vector<NumArrayType> NumArrayStoreType;
typedef boost::ptr_vector<StrArrayType> StrArrayStoreType;
StrHashType maStrPool;
svl::StringPool maStrPool;
NumArrayStoreType maNumArrays;
StrArrayStoreType maStrArrays;
rtl_uString* intern( const OUString& rStr );
};
/**
......
......@@ -2174,7 +2174,7 @@ bool appendStrings(
getBlockIterators<sc::string_block>(it, nLenRemain, itData, itDataEnd);
for (; itData != itDataEnd; ++itData)
rArray.push_back(rCxt.intern(*itData));
rArray.push_back(rCxt.maStrPool.intern(*itData));
}
break;
case sc::element_type_edittext:
......@@ -2185,7 +2185,7 @@ bool appendStrings(
for (; itData != itDataEnd; ++itData)
{
OUString aStr = ScEditUtil::GetString(**itData, pDoc);
rArray.push_back(rCxt.intern(aStr));
rArray.push_back(rCxt.maStrPool.intern(aStr));
}
}
break;
......@@ -2210,7 +2210,7 @@ bool appendStrings(
return false;
}
rArray.push_back(rCxt.intern(aStr));
rArray.push_back(rCxt.maStrPool.intern(aStr));
}
}
break;
......@@ -2250,7 +2250,7 @@ void copyFirstBlock( sc::FormulaGroupContext& rCxt, size_t nLen, const sc::CellS
const OUString* p = &sc::string_block::at(*rPos.first->data, rPos.second);
const OUString* pEnd = p + nLen;
for (; p != pEnd; ++p)
rArray.push_back(rCxt.intern(*p));
rArray.push_back(rCxt.maStrPool.intern(*p));
}
}
......
......@@ -38,23 +38,6 @@ extern "C" void compileOpenCLKernels(const OUString*);
namespace sc {
rtl_uString* FormulaGroupContext::intern( const OUString& rStr )
{
StrHashType::iterator it = maStrPool.find(rStr);
if (it == maStrPool.end())
{
// Not yet in the pool.
std::pair<StrHashType::iterator, bool> r = maStrPool.insert(rStr.intern());
if (!r.second)
// Insertion failed.
return NULL;
it = r.first;
}
return it->pData;
}
namespace {
/**
......
......@@ -110,6 +110,7 @@ $(eval $(call gb_Library_add_exception_objects,svl,\
svl/source/misc/lockfilecommon \
svl/source/misc/ownlist \
svl/source/misc/sharecontrolfile \
svl/source/misc/stringpool \
svl/source/misc/strmadpt \
svl/source/misc/urihelper \
svl/source/notify/brdcst \
......
/* -*- 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/.
*/
#include "svl/stringpool.hxx"
namespace svl {
StringPool::StringPool() {}
rtl_uString* StringPool::intern( const OUString& rStr )
{
StrHashType::iterator it = maStrPool.find(rStr);
if (it == maStrPool.end())
{
// Not yet in the pool.
std::pair<StrHashType::iterator, bool> r = maStrPool.insert(rStr.intern());
if (!r.second)
// Insertion failed.
return NULL;
it = r.first;
}
return it->pData;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment