/* This helper function walks the current policy table and returns a pointer to the best match, if any are found. Leverages EvaluatePolicyMatch() to determine "best". */
STATIC VARIABLE_POLICY_ENTRY* GetBestPolicyMatch(IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT UINT8 *ReturnPriority OPTIONAL)
/* This helper function walks the current policy table and returns a pointer to the best match, if any are found. Leverages EvaluatePolicyMatch() to determine "best". */
STATIC VARIABLE_POLICY_ENTRY* GetBestPolicyMatch(IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT UINT8 *ReturnPriority OPTIONAL)
{
  VARIABLE_POLICY_ENTRY  *BestResult;
  VARIABLE_POLICY_ENTRY  *CurrentEntry;
  UINT8                  MatchPriority;
  UINT8                  CurrentPriority;
  UINTN                  Index;
  BestResult    = NULL;
  MatchPriority = MATCH_PRIORITY_EXACT;
  CurrentEntry = (VARIABLE_POLICY_ENTRY *)mPolicyTable;
  for (Index = 0; Index < mCurrentTableCount; Index++) {
    if (EvaluatePolicyMatch (CurrentEntry, VariableName, VendorGuid, &CurrentPriority)) {
      if ((BestResult == NULL) || (CurrentPriority < MatchPriority)) {
        BestResult    = CurrentEntry;
        MatchPriority = CurrentPriority;
      }
      if (MatchPriority == 0) {
        break;
      }
    }
    CurrentEntry = GET_NEXT_POLICY (CurrentEntry);
  }
  if (ReturnPriority != NULL) {
    *ReturnPriority = MatchPriority;
  }
  return BestResult;
}