private int fastMaybeExtractCountryCode(StringBuilder nationalNumber, PhoneMetadata defaultRegionMetadata)
            throws NumberParseException
    {
        String possibleCountryIddPrefix = "NonMatch";
        if (defaultRegionMetadata != null)
        {
            possibleCountryIddPrefix = defaultRegionMetadata.getInternationalPrefix();
        }

        CountryCodeSource countryCodeSource =
                fastMaybeStripInternationalPrefixAndNormalize(nationalNumber, possibleCountryIddPrefix);

        if (countryCodeSource != CountryCodeSource.FROM_DEFAULT_COUNTRY)
        {
            if (nationalNumber.length() < MIN_LENGTH_FOR_NSN_INDIA_AND_USA)
            {
                throw new NumberParseException(NumberParseException.ErrorType.TOO_SHORT_AFTER_IDD,
                        "Phone number had an IDD, but after this was not " +
                                " long enough to be a viable phone number");
            }

            int potentialCountryCode = fastExtractCountryCode(nationalNumber);
            if (potentialCountryCode != 0)
            {
                return potentialCountryCode;
            }

            throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
                    "Country calling code supplied was not recognised.");
        }
        else if (defaultRegionMetadata != null)
        {
            int defaultCountryCode = defaultRegionMetadata.getCountryCode();
            String defaultCountryCodeString = String.valueOf(defaultCountryCode);
            String fullNumber = nationalNumber.toString();
            if (fullNumber.startsWith(defaultCountryCodeString))
            {
                nationalNumber.delete(0, defaultCountryCodeString.length());

                PhoneNumberDesc generalDesc = defaultRegionMetadata.getGeneralDesc();
                Pattern validNumberPattern =
                        regexCache.getPatternForRegex(generalDesc.getNationalNumberPattern());
                maybeStripNationalPrefixAndCarrierCode(
                        nationalNumber, defaultRegionMetadata, null /* Don't need the carrier code */);
                Pattern possibleNumberPattern =
                        regexCache.getPatternForRegex(generalDesc.getPossibleNumberPattern());

                if ((!validNumberPattern.matcher(fullNumber).matches() &&
                        validNumberPattern.matcher(nationalNumber).matches()) ||
                        testNumberLengthAgainstPattern(possibleNumberPattern, fullNumber)
                                == ValidationResult.TOO_LONG)
                {
                    return defaultCountryCode;
                }
                else
                {
                    nationalNumber.replace(0, nationalNumber.length(), fullNumber);
                }
            }
        }
        return 0;
    }