Fix a few inefficient callers of getElementsByTagName. Bug 191589,

r=neil@parkwaycc.co.uk, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2003-03-15 16:30:09 +00:00
parent a3f9865571
commit fef48cc2d0
4 changed files with 31 additions and 38 deletions

View File

@ -3993,25 +3993,23 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
// Find a matching list of named nodes
rv = htmlDoc->GetElementsByName(aAnchorName, getter_AddRefs(list));
if (NS_SUCCEEDED(rv) && list) {
PRUint32 count;
PRUint32 i;
list->GetLength(&count);
// Loop through the named nodes looking for the first anchor
for (i = 0; i < count; i++) {
for (i = 0; PR_TRUE; i++) {
nsCOMPtr<nsIDOMNode> node;
rv = list->Item(i, getter_AddRefs(node));
if (NS_FAILED(rv)) {
if (!node) { // End of list
break;
}
// Ensure it's an anchor element
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
nsAutoString tagName;
if (element && NS_SUCCEEDED(element->GetTagName(tagName))) {
ToLowerCase(tagName);
if (tagName.Equals(NS_LITERAL_STRING("a"))) {
content = do_QueryInterface(element);
content = do_QueryInterface(node);
if (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag == nsHTMLAtoms::a) {
break;
}
content = nsnull;
}
}
}
@ -4025,14 +4023,12 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
// Get the list of anchor elements
rv = doc->GetElementsByTagNameNS(nameSpace, NS_LITERAL_STRING("a"), getter_AddRefs(list));
if (NS_SUCCEEDED(rv) && list) {
PRUint32 count;
PRUint32 i;
list->GetLength(&count);
// Loop through the named nodes looking for the first anchor
for (i = 0; i < count; i++) {
for (i = 0; PR_TRUE; i++) {
nsCOMPtr<nsIDOMNode> node;
rv = list->Item(i, getter_AddRefs(node));
if (NS_FAILED(rv)) {
if (!node) { // End of list
break;
}
// Compare the name attribute

View File

@ -3993,25 +3993,23 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
// Find a matching list of named nodes
rv = htmlDoc->GetElementsByName(aAnchorName, getter_AddRefs(list));
if (NS_SUCCEEDED(rv) && list) {
PRUint32 count;
PRUint32 i;
list->GetLength(&count);
// Loop through the named nodes looking for the first anchor
for (i = 0; i < count; i++) {
for (i = 0; PR_TRUE; i++) {
nsCOMPtr<nsIDOMNode> node;
rv = list->Item(i, getter_AddRefs(node));
if (NS_FAILED(rv)) {
if (!node) { // End of list
break;
}
// Ensure it's an anchor element
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
nsAutoString tagName;
if (element && NS_SUCCEEDED(element->GetTagName(tagName))) {
ToLowerCase(tagName);
if (tagName.Equals(NS_LITERAL_STRING("a"))) {
content = do_QueryInterface(element);
content = do_QueryInterface(node);
if (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag == nsHTMLAtoms::a) {
break;
}
content = nsnull;
}
}
}
@ -4025,14 +4023,12 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
// Get the list of anchor elements
rv = doc->GetElementsByTagNameNS(nameSpace, NS_LITERAL_STRING("a"), getter_AddRefs(list));
if (NS_SUCCEEDED(rv) && list) {
PRUint32 count;
PRUint32 i;
list->GetLength(&count);
// Loop through the named nodes looking for the first anchor
for (i = 0; i < count; i++) {
for (i = 0; PR_TRUE; i++) {
nsCOMPtr<nsIDOMNode> node;
rv = list->Item(i, getter_AddRefs(node));
if (NS_FAILED(rv)) {
if (!node) { // End of list
break;
}
// Compare the name attribute

View File

@ -1575,7 +1575,7 @@
<body><![CDATA[
var textbox = document.getBindingParent(this);
var kids = textbox.getElementsByTagName("menupopup");
if (kids.length) {
if (kids.item(0)) {
kids[0].showPopup(textbox, -1, -1, "popup", "bottomleft", "topleft");
textbox.setAttribute("open", true);
}

View File

@ -72,11 +72,13 @@ function SortColumn(columnID)
function find_sort_column()
{
var columns = document.getElementsByTagName('treecol');
for (var i = 0; i < columns.length; ++i) {
if (columns[i].getAttribute('sortDirection'))
return columns[i];
var i = 0;
var column;
while ((column = columns.item(i++)) != null) {
if (column.getAttribute('sortDirection'))
return column;
}
return columns[0];
return columns.item(0);
}
// get the sort direction for the given column
@ -160,7 +162,6 @@ function fillViewMenu(popup)
{
var fill_after = document.getElementById('fill_after_this_node');
var fill_before = document.getElementById('fill_before_this_node');
var columns = document.getElementsByTagName('treecol');
var strBundle = document.getElementById('sortBundle');
var sortString;
if (strBundle)
@ -168,11 +169,11 @@ function fillViewMenu(popup)
if (!sortString)
sortString = "Sorted by %COLNAME%";
var popupChild = popup.firstChild.nextSibling.nextSibling;
var firstTime = (fill_after.nextSibling == fill_before);
for (var i = 0; i < columns.length; ++i) {
var column = columns[i];
if (firstTime) {
if (firstTime) {
var columns = document.getElementsByTagName('treecol');
for (var i = 0; i < columns.length; ++i) {
var column = columns[i];
// Construct an entry for each cell in the row.
var column_name = column.getAttribute("label");
var item = document.createElement("menuitem");