gfx/graphite2/src/inc/SegCacheEntry.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms of the
michael@0 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
michael@0 24 License, as published by the Free Software Foundation, either version 2
michael@0 25 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 #pragma once
michael@0 28
michael@0 29 #ifndef GRAPHITE2_NSEGCACHE
michael@0 30
michael@0 31 #include "inc/Main.h"
michael@0 32 #include "inc/Slot.h"
michael@0 33
michael@0 34 namespace graphite2 {
michael@0 35
michael@0 36 class Segment;
michael@0 37 class Slot;
michael@0 38 class SegCacheEntry;
michael@0 39 class SegCachePrefixEntry;
michael@0 40
michael@0 41 enum SegCacheParameters {
michael@0 42 /** number of characters used in initial prefix tree */
michael@0 43 ePrefixLength = 2,
michael@0 44 /** Segments more recent than maxSegmentCount() / eAgeFactor are kept */
michael@0 45 eAgeFactor = 4,
michael@0 46 /** Segments are purged according to the formular:
michael@0 47 * accessCount < (totalAccesses)/(ePurgeFactor * maxSegments) */
michael@0 48 ePurgeFactor = 5,
michael@0 49 /** Maximum number of Segments to store which have the same
michael@0 50 * prefix. Needed to prevent unique identifiers flooding the cache */
michael@0 51 eMaxSuffixCount = 15
michael@0 52
michael@0 53 };
michael@0 54
michael@0 55 class SegCacheCharInfo
michael@0 56 {
michael@0 57 public:
michael@0 58 uint16 m_unicode;
michael@0 59 uint16 m_before;
michael@0 60 uint16 m_after;
michael@0 61 };
michael@0 62
michael@0 63 /**
michael@0 64 * SegCacheEntry stores the result of running the engine for specific unicode
michael@0 65 * code points in the typical mid-line situation.
michael@0 66 */
michael@0 67 class SegCacheEntry
michael@0 68 {
michael@0 69 // Prevent any implict copying;
michael@0 70 SegCacheEntry(const SegCacheEntry &);
michael@0 71 SegCacheEntry & operator = (const SegCacheEntry &);
michael@0 72
michael@0 73 friend class SegCachePrefixEntry;
michael@0 74 public:
michael@0 75 SegCacheEntry() :
michael@0 76 m_glyphLength(0), m_unicode(NULL), m_glyph(NULL), m_attr(NULL), m_justs(0),
michael@0 77 m_accessCount(0), m_lastAccess(0)
michael@0 78 {}
michael@0 79 SegCacheEntry(const uint16 * cmapGlyphs, size_t length, Segment * seg, size_t charOffset, long long cacheTime);
michael@0 80 ~SegCacheEntry() { clear(); };
michael@0 81 void clear();
michael@0 82 size_t glyphLength() const { return m_glyphLength; }
michael@0 83 const Slot * first() const { return m_glyph; }
michael@0 84 const Slot * last() const { return m_glyph + (m_glyphLength - 1); }
michael@0 85
michael@0 86 /** Total number of times this entry has been accessed since creation */
michael@0 87 unsigned long long accessCount() const { return m_accessCount; }
michael@0 88 /** "time" of last access where "time" is measured in accesses to the cache owning this entry */
michael@0 89 void accessed(unsigned long long cacheTime) const
michael@0 90 {
michael@0 91 m_lastAccess = cacheTime; ++m_accessCount;
michael@0 92 };
michael@0 93
michael@0 94 int compareRank(const SegCacheEntry & entry) const
michael@0 95 {
michael@0 96 if (m_accessCount > entry.m_accessCount) return 1;
michael@0 97 else if (m_accessCount < entry.m_accessCount) return 1;
michael@0 98 else if (m_lastAccess > entry.m_lastAccess) return 1;
michael@0 99 else if (m_lastAccess < entry.m_lastAccess) return -1;
michael@0 100 return 0;
michael@0 101 }
michael@0 102 unsigned long long lastAccess() const { return m_lastAccess; };
michael@0 103
michael@0 104 CLASS_NEW_DELETE;
michael@0 105 private:
michael@0 106
michael@0 107 size_t m_glyphLength;
michael@0 108 /** glyph ids resulting from cmap mapping from unicode to glyph before substitution
michael@0 109 * the length of this array is determined by the position in the SegCachePrefixEntry */
michael@0 110 uint16 * m_unicode;
michael@0 111 /** slots after shapping and positioning */
michael@0 112 Slot * m_glyph;
michael@0 113 int16 * m_attr;
michael@0 114 byte * m_justs;
michael@0 115 mutable unsigned long long m_accessCount;
michael@0 116 mutable unsigned long long m_lastAccess;
michael@0 117 };
michael@0 118
michael@0 119 } // namespace graphite2
michael@0 120
michael@0 121 #endif

mercurial