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

Side by Side Diff: Source/core/editing/markup.cpp

Issue 171953002: Get rid of inefficient uses of childNodeCount() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Small clean up Created 6 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2011 Igalia S.L. 4 * Copyright (C) 2011 Igalia S.L.
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 next = NodeTraversal::nextSkippingChildren(*n); 362 next = NodeTraversal::nextSkippingChildren(*n);
363 // Don't skip over pastEnd. 363 // Don't skip over pastEnd.
364 if (pastEnd && pastEnd->isDescendantOf(n)) 364 if (pastEnd && pastEnd->isDescendantOf(n))
365 next = pastEnd; 365 next = pastEnd;
366 } else { 366 } else {
367 // Add the node to the markup if we're not skipping the descendants 367 // Add the node to the markup if we're not skipping the descendants
368 if (shouldEmit) 368 if (shouldEmit)
369 appendStartTag(*n); 369 appendStartTag(*n);
370 370
371 // If node has no children, close the tag now. 371 // If node has no children, close the tag now.
372 if (!n->childNodeCount()) { 372 if (!n->hasChildNodes()) {
373 if (shouldEmit) 373 if (shouldEmit)
374 appendEndTag(*n); 374 appendEndTag(*n);
375 lastClosed = n; 375 lastClosed = n;
376 } else { 376 } else {
377 openedTag = true; 377 openedTag = true;
378 ancestorsToClose.append(n); 378 ancestorsToClose.append(n);
379 } 379 }
380 } 380 }
381 381
382 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors. 382 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors.
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // (if the last character is a tab, the list gets an extra empty entry) 775 // (if the last character is a tab, the list gets an extra empty entry)
776 if (i + 1 != numEntries) 776 if (i + 1 != numEntries)
777 tabText.append('\t'); 777 tabText.append('\t');
778 else if (!tabText.isEmpty()) 778 else if (!tabText.isEmpty())
779 paragraph->appendChild(createTabSpanElement(document, tabText.toStri ng())); 779 paragraph->appendChild(createTabSpanElement(document, tabText.toStri ng()));
780 780
781 first = false; 781 first = false;
782 } 782 }
783 } 783 }
784 784
785 bool isPlainTextMarkup(Node *node) 785 bool isPlainTextMarkup(Node* node)
786 { 786 {
787 if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)-> hasAttributes()) 787 if (!node->isElementNode())
788 return false; 788 return false;
789 789
790 if (node->childNodeCount() == 1 && (node->firstChild()->isTextNode() || (nod e->firstChild()->firstChild()))) 790 Element* element = toElement(node);
791 if (!element->hasTagName(divTag) || !element->hasAttributes())
792 return false;
793
794 if (element->hasOneChild() && (element->firstChild()->isTextNode() || (eleme nt->firstChild()->firstChild())))
791 return true; 795 return true;
792 796
793 return (node->childNodeCount() == 2 && isTabSpanTextNode(node->firstChild()- >firstChild()) && node->firstChild()->nextSibling()->isTextNode()); 797 bool elementHasTwoChildren = (element->firstChild() && element->firstChild() ->nextSibling() && !element->firstChild()->nextSibling()->nextSibling());
eseidel 2014/02/19 05:39:54 I wonder if a generic hasChildCount(unsigned) is u
Inactive 2014/02/19 14:28:15 This is likely the only place where we would need
798 return (elementHasTwoChildren && isTabSpanTextNode(element->firstChild()->fi rstChild()) && element->firstChild()->nextSibling()->isTextNode());
794 } 799 }
795 800
796 static bool shouldPreserveNewline(const Range& range) 801 static bool shouldPreserveNewline(const Range& range)
797 { 802 {
798 if (Node* node = range.firstNode()) { 803 if (Node* node = range.firstNode()) {
799 if (RenderObject* renderer = node->renderer()) 804 if (RenderObject* renderer = node->renderer())
800 return renderer->style()->preserveNewline(); 805 return renderer->style()->preserveNewline();
801 } 806 }
802 807
803 if (Node* node = range.startPosition().anchorNode()) { 808 if (Node* node = range.startPosition().anchorNode()) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 return; 1049 return;
1045 1050
1046 RefPtr<Text> textNode = toText(node.get()); 1051 RefPtr<Text> textNode = toText(node.get());
1047 RefPtr<Text> textNext = toText(next); 1052 RefPtr<Text> textNext = toText(next);
1048 textNode->appendData(textNext->data()); 1053 textNode->appendData(textNext->data());
1049 if (textNext->parentNode()) // Might have been removed by mutation event. 1054 if (textNext->parentNode()) // Might have been removed by mutation event.
1050 textNext->remove(exceptionState); 1055 textNext->remove(exceptionState);
1051 } 1056 }
1052 1057
1053 } 1058 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698