mControls->mElements.AppendElement(aChild);
PRUint32 count; GetElementCount(&count);  nsCOMPtr<nsIFormControl> element;   PRInt32 position = -1; if (count > 0) { GetElementAt(count - 1, getter_AddRefs(element)); position = CompareFormControlPosition(aChild, element); }     if (position >= 0 || count == 0) {  mControls->mElements.AppendElement(aChild); } else { PRInt32 low = 0, mid, high; high = count - 1;  while (low <= high) { mid = (low + high) / 2;  GetElementAt(mid, getter_AddRefs(element)); position = CompareFormControlPosition(aChild, element); if (position >= 0) low = mid + 1; else high = mid - 1; }   mControls->mElements.InsertElementAt(aChild, low); }
nsHTMLFormElement::AddElement(nsIFormControl* aChild){  NS_ENSURE_TRUE(mControls, NS_ERROR_UNEXPECTED);  if (ShouldBeInElements(aChild)) {    // WEAK - don't addref    mControls->mElements.AppendElement(aChild);  } else {    // WEAK - don't addref    mControls->mNotInElements.AppendElement(aChild);  }  //  // Notify the radio button it's been added to a group  //  PRInt32 type = aChild->GetType();  if (type == NS_FORM_INPUT_RADIO) {    nsCOMPtr<nsIRadioControlElement> radio = do_QueryInterface(aChild);    nsresult rv = radio->AddedToRadioGroup();    NS_ENSURE_SUCCESS(rv, rv);  }  //  // If it is a password control, and the password manager has not yet been  // initialized, initialize the password manager  //  if (!gPasswordManagerInitialized && type == NS_FORM_INPUT_PASSWORD) {    // Initialize the password manager category    gPasswordManagerInitialized = PR_TRUE;    NS_CreateServicesFromCategory(NS_PASSWORDMANAGER_CATEGORY,                                  nsnull,                                  NS_PASSWORDMANAGER_CATEGORY);  }  return NS_OK;}