Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: Source/core/html/parser/HTMLTreeBuilder.cpp

Issue 51983003: Stop using static arrays for *Tags / *Attrs (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->has TagName(divTag) && !item->hasTagName(pTag)) 542 if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->has TagName(divTag) && !item->hasTagName(pTag))
543 break; 543 break;
544 nodeRecord = nodeRecord->next(); 544 nodeRecord = nodeRecord->next();
545 } 545 }
546 processFakePEndTagIfPInButtonScope(); 546 processFakePEndTagIfPInButtonScope();
547 m_tree.insertHTMLElement(token); 547 m_tree.insertHTMLElement(token);
548 } 548 }
549 549
550 typedef HashMap<AtomicString, QualifiedName> PrefixedNameToQualifiedNameMap; 550 typedef HashMap<AtomicString, QualifiedName> PrefixedNameToQualifiedNameMap;
551 551
552 static void mapLoweredLocalNameToName(PrefixedNameToQualifiedNameMap* map, const QualifiedName* const* names, size_t length) 552 static void mapLoweredLocalNameToName(PrefixedNameToQualifiedNameMap* map, const Vector<const QualifiedName*>& names)
553 { 553 {
554 size_t length = names.size();
554 for (size_t i = 0; i < length; ++i) { 555 for (size_t i = 0; i < length; ++i) {
555 const QualifiedName& name = *names[i]; 556 const QualifiedName& name = *names[i];
556 const AtomicString& localName = name.localName(); 557 const AtomicString& localName = name.localName();
557 AtomicString loweredLocalName = localName.lower(); 558 AtomicString loweredLocalName = localName.lower();
558 if (loweredLocalName != localName) 559 if (loweredLocalName != localName)
559 map->add(loweredLocalName, name); 560 map->add(loweredLocalName, name);
560 } 561 }
561 } 562 }
562 563
563 static void adjustSVGTagNameCase(AtomicHTMLToken* token) 564 static void adjustSVGTagNameCase(AtomicHTMLToken* token)
564 { 565 {
565 static PrefixedNameToQualifiedNameMap* caseMap = 0; 566 static PrefixedNameToQualifiedNameMap* caseMap = 0;
566 if (!caseMap) { 567 if (!caseMap) {
567 caseMap = new PrefixedNameToQualifiedNameMap; 568 caseMap = new PrefixedNameToQualifiedNameMap;
568 const QualifiedName* const* svgTags = SVGNames::getSVGTags(); 569 Vector<const QualifiedName*> svgTags;
569 mapLoweredLocalNameToName(caseMap, svgTags, SVGNames::SVGTagsCount); 570 SVGNames::getSVGTags(svgTags);
571 mapLoweredLocalNameToName(caseMap, svgTags);
570 } 572 }
571 573
572 const QualifiedName& casedName = caseMap->get(token->name()); 574 const QualifiedName& casedName = caseMap->get(token->name());
573 if (casedName.localName().isNull()) 575 if (casedName.localName().isNull())
574 return; 576 return;
575 token->setName(casedName.localName()); 577 token->setName(casedName.localName());
576 } 578 }
577 579
578 template<const QualifiedName* const* getAttrs(), unsigned length> 580 template<void getAttrs(Vector<const QualifiedName*>&)>
579 static void adjustAttributes(AtomicHTMLToken* token) 581 static void adjustAttributes(AtomicHTMLToken* token)
580 { 582 {
581 static PrefixedNameToQualifiedNameMap* caseMap = 0; 583 static PrefixedNameToQualifiedNameMap* caseMap = 0;
582 if (!caseMap) { 584 if (!caseMap) {
583 caseMap = new PrefixedNameToQualifiedNameMap; 585 caseMap = new PrefixedNameToQualifiedNameMap;
584 const QualifiedName* const* attrs = getAttrs(); 586 Vector<const QualifiedName*> attrs;
585 mapLoweredLocalNameToName(caseMap, attrs, length); 587 getAttrs(attrs);
588 mapLoweredLocalNameToName(caseMap, attrs);
586 } 589 }
587 590
588 for (unsigned i = 0; i < token->attributes().size(); ++i) { 591 for (unsigned i = 0; i < token->attributes().size(); ++i) {
589 Attribute& tokenAttribute = token->attributes().at(i); 592 Attribute& tokenAttribute = token->attributes().at(i);
590 const QualifiedName& casedName = caseMap->get(tokenAttribute.localName() ); 593 const QualifiedName& casedName = caseMap->get(tokenAttribute.localName() );
591 if (!casedName.localName().isNull()) 594 if (!casedName.localName().isNull())
592 tokenAttribute.parserSetName(casedName); 595 tokenAttribute.parserSetName(casedName);
593 } 596 }
594 } 597 }
595 598
596 static void adjustSVGAttributes(AtomicHTMLToken* token) 599 static void adjustSVGAttributes(AtomicHTMLToken* token)
597 { 600 {
598 adjustAttributes<SVGNames::getSVGAttrs, SVGNames::SVGAttrsCount>(token); 601 adjustAttributes<SVGNames::getSVGAttrs>(token);
599 } 602 }
600 603
601 static void adjustMathMLAttributes(AtomicHTMLToken* token) 604 static void adjustMathMLAttributes(AtomicHTMLToken* token)
602 { 605 {
603 adjustAttributes<MathMLNames::getMathMLAttrs, MathMLNames::MathMLAttrsCount> (token); 606 adjustAttributes<MathMLNames::getMathMLAttrs>(token);
604 } 607 }
605 608
606 static void addNamesWithPrefix(PrefixedNameToQualifiedNameMap* map, const Atomic String& prefix, const QualifiedName* const* names, size_t length) 609 static void addNamesWithPrefix(PrefixedNameToQualifiedNameMap* map, const Atomic String& prefix, const Vector<const QualifiedName*>& names)
607 { 610 {
611 size_t length = names.size();
608 for (size_t i = 0; i < length; ++i) { 612 for (size_t i = 0; i < length; ++i) {
609 const QualifiedName* name = names[i]; 613 const QualifiedName* name = names[i];
610 const AtomicString& localName = name->localName(); 614 const AtomicString& localName = name->localName();
611 AtomicString prefixColonLocalName = prefix + ':' + localName; 615 AtomicString prefixColonLocalName = prefix + ':' + localName;
612 QualifiedName nameWithPrefix(prefix, localName, name->namespaceURI()); 616 QualifiedName nameWithPrefix(prefix, localName, name->namespaceURI());
613 map->add(prefixColonLocalName, nameWithPrefix); 617 map->add(prefixColonLocalName, nameWithPrefix);
614 } 618 }
615 } 619 }
616 620
617 static void adjustForeignAttributes(AtomicHTMLToken* token) 621 static void adjustForeignAttributes(AtomicHTMLToken* token)
618 { 622 {
619 static PrefixedNameToQualifiedNameMap* map = 0; 623 static PrefixedNameToQualifiedNameMap* map = 0;
620 if (!map) { 624 if (!map) {
621 map = new PrefixedNameToQualifiedNameMap; 625 map = new PrefixedNameToQualifiedNameMap;
622 626
623 const QualifiedName* const* attrs = XLinkNames::getXLinkAttrs(); 627 Vector<const QualifiedName*> attrs;
624 addNamesWithPrefix(map, xlinkAtom, attrs, XLinkNames::XLinkAttrsCount); 628 XLinkNames::getXLinkAttrs(attrs);
629 addNamesWithPrefix(map, xlinkAtom, attrs);
625 630
626 attrs = XMLNames::getXMLAttrs(); 631 XMLNames::getXMLAttrs(attrs);
627 addNamesWithPrefix(map, xmlAtom, attrs, XMLNames::XMLAttrsCount); 632 addNamesWithPrefix(map, xmlAtom, attrs);
628 633
629 map->add(WTF::xmlnsAtom, XMLNSNames::xmlnsAttr); 634 map->add(WTF::xmlnsAtom, XMLNSNames::xmlnsAttr);
630 map->add("xmlns:xlink", QualifiedName(xmlnsAtom, xlinkAtom, XMLNSNames:: xmlnsNamespaceURI)); 635 map->add("xmlns:xlink", QualifiedName(xmlnsAtom, xlinkAtom, XMLNSNames:: xmlnsNamespaceURI));
631 } 636 }
632 637
633 for (unsigned i = 0; i < token->attributes().size(); ++i) { 638 for (unsigned i = 0; i < token->attributes().size(); ++i) {
634 Attribute& tokenAttribute = token->attributes().at(i); 639 Attribute& tokenAttribute = token->attributes().at(i);
635 const QualifiedName& name = map->get(tokenAttribute.localName()); 640 const QualifiedName& name = map->get(tokenAttribute.localName());
636 if (!name.localName().isNull()) 641 if (!name.localName().isNull())
637 tokenAttribute.parserSetName(name); 642 tokenAttribute.parserSetName(name);
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 ASSERT(m_isAttached); 2843 ASSERT(m_isAttached);
2839 // Warning, this may detach the parser. Do not do anything else after this. 2844 // Warning, this may detach the parser. Do not do anything else after this.
2840 m_tree.finishedParsing(); 2845 m_tree.finishedParsing();
2841 } 2846 }
2842 2847
2843 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) 2848 void HTMLTreeBuilder::parseError(AtomicHTMLToken*)
2844 { 2849 {
2845 } 2850 }
2846 2851
2847 } // namespace WebCore 2852 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698