+ return stab_best;
+}
+
+/* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
+ the global block of PST if GLOBAL, and otherwise the static block.
+ MATCH is the comparison operation that returns true iff MATCH (s,
+ NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
+ non-null, the symbols in the block are assumed to be ordered
+ according to it (allowing binary search). It must be compatible
+ with MATCH. Returns the symbol, if found, and otherwise NULL. */
+
+static struct partial_symbol *
+match_partial_symbol (struct objfile *objfile,
+ struct partial_symtab *pst, int global,
+ const char *name, domain_enum domain,
+ symbol_compare_ftype *match,
+ symbol_compare_ftype *ordered_compare)
+{
+ struct partial_symbol **start, **psym;
+ struct partial_symbol **top, **real_top, **bottom, **center;
+ int length = (global ? pst->n_global_syms : pst->n_static_syms);
+ int do_linear_search = 1;
+
+ if (length == 0)
+ return NULL;
+ start = (global ?
+ objfile->global_psymbols.list + pst->globals_offset :
+ objfile->static_psymbols.list + pst->statics_offset);
+
+ if (global && ordered_compare) /* Can use a binary search. */
+ {
+ do_linear_search = 0;
+
+ /* Binary search. This search is guaranteed to end with center
+ pointing at the earliest partial symbol whose name might be
+ correct. At that point *all* partial symbols with an
+ appropriate name will be checked against the correct
+ domain. */
+
+ bottom = start;
+ top = start + length - 1;
+ real_top = top;
+ while (top > bottom)
+ {
+ center = bottom + (top - bottom) / 2;
+ gdb_assert (center < top);
+ if (!do_linear_search
+ && (SYMBOL_LANGUAGE (*center) == language_java))
+ do_linear_search = 1;
+ if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
+ top = center;
+ else
+ bottom = center + 1;
+ }
+ gdb_assert (top == bottom);
+
+ while (top <= real_top
+ && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
+ {
+ if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
+ SYMBOL_DOMAIN (*top), domain))
+ return *top;
+ top++;
+ }
+ }
+
+ /* Can't use a binary search or else we found during the binary search that
+ we should also do a linear search. */
+
+ if (do_linear_search)
+ {
+ for (psym = start; psym < start + length; psym++)
+ {
+ if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
+ SYMBOL_DOMAIN (*psym), domain)
+ && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
+ return *psym;
+ }
+ }
+