for (i = 0; i < count; i++) { array[i] = (nsMenuEntry *)aArray->ElementAt(i);
for (i = 0; i < count && NS_SUCCEEDED(res); i++) { array[i].item = (nsMenuEntry *)aArray->ElementAt(i);  res = collation->GetSortKeyLen(kCollationCaseInSensitive, (array[i].item)->mTitle, &array[i].len);  if (NS_SUCCEEDED(res)) { array[i].key = new PRUint8 [array[i].len]; if (!(array[i].key)) { res = NS_ERROR_OUT_OF_MEMORY; goto done; } res = collation->CreateRawSortKey(kCollationCaseInSensitive, (array[i].item)->mTitle, array[i].key, &array[i].len); }
nsresult nsCharsetMenu::ReorderMenuItemArray(nsVoidArray * aArray){  nsresult res = NS_OK;  nsCOMPtr<nsICollation> collation;  PRUint32 count = aArray->Count();  PRUint32 i;  // we need to use a temporary array  nsMenuEntry ** array = new nsMenuEntry * [count];  if (array == NULL) {    res = NS_ERROR_OUT_OF_MEMORY;    goto done;  }  for (i = 0; i < count; i++) {    array[i] = (nsMenuEntry *)aArray->ElementAt(i);  }  // reorder the array  res = GetCollation(getter_AddRefs(collation));  if (NS_SUCCEEDED(res))     NS_QuickSort(array, count, sizeof(*array), CompareMenuItems, collation);  // move the elements from the temporary array into the the real one  aArray->Clear();  for (i = 0; i < count; i++) {    aArray->AppendElement(array[i]);  }done:  delete [] array;  return res;}