Modified: trunk/Source/WebCore/ChangeLog (102070 => 102071)
--- trunk/Source/WebCore/ChangeLog 2011-12-06 00:43:12 UTC (rev 102070)
+++ trunk/Source/WebCore/ChangeLog 2011-12-06 01:03:53 UTC (rev 102071)
@@ -1,3 +1,20 @@
+2011-12-05 Darin Adler <[email protected]>
+
+ Change CSSFontSelector to use HashMap<OwnPtr>
+ https://bugs.webkit.org/show_bug.cgi?id=73781
+
+ Reviewed by Dan Bernstein.
+
+ * css/CSSFontSelector.cpp:
+ (WebCore::CSSFontSelector::~CSSFontSelector): Removed calls to deleteAllValues.
+ (WebCore::CSSFontSelector::addFontFaceRule): Updated to use OwnPtr instead of raw
+ pointer for the entry in m_fontFaces and m_locallyInstalledFontFaces.
+ (WebCore::CSSFontSelector::getFontData): Updated to use OwnPtr instead of raw
+ pointer for the entry in m_fonts. Also removed an unneeded std:: prefix.
+
+ * css/CSSFontSelector.h: Made m_fontFaces, m_locallyInstalledFontFaces, and m_fonts
+ be HashMap<OwnPtr>.
+
2011-12-05 Adam Klein <[email protected]>
V8RecursionScope should call didLeaveScriptContext when recursionLevel reaches zero
Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (102070 => 102071)
--- trunk/Source/WebCore/css/CSSFontSelector.cpp 2011-12-06 00:43:12 UTC (rev 102070)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp 2011-12-06 01:03:53 UTC (rev 102071)
@@ -56,6 +56,8 @@
#include "SVGNames.h"
#endif
+using namespace std;
+
namespace WebCore {
CSSFontSelector::CSSFontSelector(Document* document)
@@ -74,9 +76,6 @@
{
clearDocument();
fontCache()->removeClient(this);
- deleteAllValues(m_fontFaces);
- deleteAllValues(m_locallyInstalledFontFaces);
- deleteAllValues(m_fonts);
}
bool CSSFontSelector::isEmpty() const
@@ -320,20 +319,16 @@
if (familyName.isEmpty())
continue;
- Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(familyName);
+ OwnPtr<Vector<RefPtr<CSSFontFace> > >& familyFontFaces = m_fontFaces.add(familyName, nullptr).first->second;
if (!familyFontFaces) {
- familyFontFaces = new Vector<RefPtr<CSSFontFace> >;
- m_fontFaces.set(familyName, familyFontFaces);
+ familyFontFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >);
ASSERT(!m_locallyInstalledFontFaces.contains(familyName));
- Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFaces;
Vector<unsigned> locallyInstalledFontsTraitsMasks;
fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTraitsMasks);
- unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsMasks.size();
- if (numLocallyInstalledFaces) {
- familyLocallyInstalledFaces = new Vector<RefPtr<CSSFontFace> >;
- m_locallyInstalledFontFaces.set(familyName, familyLocallyInstalledFaces);
+ if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsMasks.size()) {
+ OwnPtr<Vector<RefPtr<CSSFontFace> > > familyLocallyInstalledFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >);
for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) {
RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace::create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), true);
@@ -341,6 +336,8 @@
ASSERT(locallyInstalledFontFace->isValid());
familyLocallyInstalledFaces->append(locallyInstalledFontFace);
}
+
+ m_locallyInstalledFontFaces.set(familyName, familyLocallyInstalledFaces.release());
}
}
@@ -522,19 +519,16 @@
return fontDataForGenericFamily(m_document, fontDescription, familyName);
}
- HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >* segmentedFontFaceCache = m_fonts.get(family);
- if (!segmentedFontFaceCache) {
- segmentedFontFaceCache = new HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >;
- m_fonts.set(family, segmentedFontFaceCache);
- }
+ OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >& segmentedFontFaceCache = m_fonts.add(family, nullptr).first->second;
+ if (!segmentedFontFaceCache)
+ segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >);
FontTraitsMask traitsMask = fontDescription.traitsMask();
- RefPtr<CSSSegmentedFontFace> face = segmentedFontFaceCache->get(traitsMask);
-
+ RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, 0).first->second;
if (!face) {
face = CSSSegmentedFontFace::create(this);
- segmentedFontFaceCache->set(traitsMask, face);
+
// Collect all matching faces and sort them in order of preference.
Vector<CSSFontFace*, 32> candidateFontFaces;
for (int i = familyFontFaces->size() - 1; i >= 0; --i) {
@@ -567,7 +561,7 @@
}
desiredTraitsMaskForComparison = traitsMask;
- std::stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFontFaces);
+ stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compareFontFaces);
unsigned numCandidates = candidateFontFaces.size();
for (unsigned i = 0; i < numCandidates; ++i)
face->appendFontFace(candidateFontFaces[i]);
Modified: trunk/Source/WebCore/css/CSSFontSelector.h (102070 => 102071)
--- trunk/Source/WebCore/css/CSSFontSelector.h 2011-12-06 00:43:12 UTC (rev 102070)
+++ trunk/Source/WebCore/css/CSSFontSelector.h 2011-12-06 01:03:53 UTC (rev 102071)
@@ -78,9 +78,9 @@
void beginLoadTimerFired(Timer<CSSFontSelector>*);
Document* m_document;
- HashMap<String, Vector<RefPtr<CSSFontFace> >*, CaseFoldingHash> m_fontFaces;
- HashMap<String, Vector<RefPtr<CSSFontFace> >*, CaseFoldingHash> m_locallyInstalledFontFaces;
- HashMap<String, HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >*, CaseFoldingHash> m_fonts;
+ HashMap<String, OwnPtr<Vector<RefPtr<CSSFontFace> > >, CaseFoldingHash> m_fontFaces;
+ HashMap<String, OwnPtr<Vector<RefPtr<CSSFontFace> > >, CaseFoldingHash> m_locallyInstalledFontFaces;
+ HashMap<String, OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >, CaseFoldingHash> m_fonts;
HashSet<FontSelectorClient*> m_clients;
Vector<CachedResourceHandle<CachedFont> > m_fontsToBeginLoading;