mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-01-30 17:14:50 +01:00
Optimization - mutex replaced by read/write lock
This commit is contained in:
parent
290c769cc3
commit
03c454951e
@ -29,6 +29,7 @@
|
|||||||
#include <freetype/t1tables.h>
|
#include <freetype/t1tables.h>
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
@ -426,11 +427,11 @@ private:
|
|||||||
/// Function checks, if error occured, and if yes, then exception is thrown
|
/// Function checks, if error occured, and if yes, then exception is thrown
|
||||||
static void checkFreeTypeError(FT_Error error);
|
static void checkFreeTypeError(FT_Error error);
|
||||||
|
|
||||||
/// Mutex for accessing the glyph data
|
/// Read/write lock for accessing the glyph data
|
||||||
QMutex m_mutex;
|
QReadWriteLock m_readWriteLock;
|
||||||
|
|
||||||
/// Glyph cache, must be protected by the mutex above
|
/// Glyph cache, must be protected by the mutex above
|
||||||
std::map<unsigned int, Glyph> m_glyphCache;
|
std::unordered_map<unsigned int, Glyph> m_glyphCache;
|
||||||
|
|
||||||
/// For embedded fonts, this byte array contains embedded font data
|
/// For embedded fonts, this byte array contains embedded font data
|
||||||
QByteArray m_embeddedFontData;
|
QByteArray m_embeddedFontData;
|
||||||
@ -818,17 +819,20 @@ int PDFRealizedFontImpl::outlineCubicTo(const FT_Vector* control1, const FT_Vect
|
|||||||
|
|
||||||
const PDFRealizedFontImpl::Glyph& PDFRealizedFontImpl::getGlyph(unsigned int glyphIndex)
|
const PDFRealizedFontImpl::Glyph& PDFRealizedFontImpl::getGlyph(unsigned int glyphIndex)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
|
||||||
|
|
||||||
// First look into cache
|
|
||||||
auto it = m_glyphCache.find(glyphIndex);
|
|
||||||
if (it != m_glyphCache.cend())
|
|
||||||
{
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glyphIndex)
|
if (glyphIndex)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
QReadLocker readLock(&m_readWriteLock);
|
||||||
|
|
||||||
|
// First look into cache
|
||||||
|
auto it = m_glyphCache.find(glyphIndex);
|
||||||
|
if (it != m_glyphCache.cend())
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QWriteLocker writeLock(&m_readWriteLock);
|
||||||
Glyph glyph;
|
Glyph glyph;
|
||||||
|
|
||||||
FT_Outline_Funcs glyphOutlineInterface;
|
FT_Outline_Funcs glyphOutlineInterface;
|
||||||
@ -845,8 +849,12 @@ const PDFRealizedFontImpl::Glyph& PDFRealizedFontImpl::getGlyph(unsigned int gly
|
|||||||
glyph.advance = !m_isVertical ? m_face->glyph->advance.x : m_face->glyph->advance.y;
|
glyph.advance = !m_isVertical ? m_face->glyph->advance.x : m_face->glyph->advance.y;
|
||||||
glyph.advance *= FONT_MULTIPLIER;
|
glyph.advance *= FONT_MULTIPLIER;
|
||||||
|
|
||||||
m_glyphCache[glyphIndex] = qMove(glyph);
|
auto it = m_glyphCache.find(glyphIndex);
|
||||||
return m_glyphCache[glyphIndex];
|
if (it == m_glyphCache.cend())
|
||||||
|
{
|
||||||
|
it = m_glyphCache.insert(std::make_pair(glyphIndex, qMove(glyph))).first;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Glyph dummy;
|
static Glyph dummy;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user