<commit_before>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

// N.B.: This free function has been manually specialized below where
// `UTF8CodeUnits == UnsafeBufferPoint<UInt8>`. Ensure that any changes are
// made in sync.
@_alwaysEmitIntoClient
internal func _parseASCIIDigits<
  UTF8CodeUnits: Collection, Result: FixedWidthInteger
>(
  _ codeUnits: UTF8CodeUnits, radix: Int, isNegative: Bool
) -> Result? where UTF8CodeUnits.Element == UInt8 {
  _internalInvariant(radix >= 2 && radix <= 36)
  guard _fastPath(!codeUnits.isEmpty) else { return nil }
  let multiplicand = Result(radix)
  var result = 0 as Result
  if radix <= 10 {
    let upperBound = 48 /* "0" */ &+ UInt8(radix)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 && digit < upperBound) {
        digitValue = Result(digit &- 48)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  } else {
    let uppercaseUpperBound = 65 /* "A" */ &+ UInt8(radix &- 10)
    let lowercaseUpperBound = 97 /* "a" */ &+ UInt8(radix &- 10)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 /* "0" */ && digit < 58) {
        digitValue = Result(digit &- 48)
      } else if _fastPath(digit >= 65 && digit < uppercaseUpperBound) {
        digitValue = Result(digit &- 65 &+ 10)
      } else if _fastPath(digit >= 97 && digit < lowercaseUpperBound) {
        digitValue = Result(digit &- 97 &+ 10)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  }
  return result
}

// N.B.: This free function is a manually specialized version of the function
// above. Ensure that any changes are made in sync.
@_alwaysEmitIntoClient
internal func _parseASCIIDigits<Result: FixedWidthInteger>(
  _ codeUnits: UnsafeBufferPointer<UInt8>, radix: Int, isNegative: Bool
) -> Result? {
  _internalInvariant(radix >= 2 && radix <= 36)
  guard _fastPath(!codeUnits.isEmpty) else { return nil }
  let multiplicand = Result(radix)
  var result = 0 as Result
  if radix <= 10 {
    let upperBound = 48 /* "0" */ &+ UInt8(radix)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 && digit < upperBound) {
        digitValue = Result(digit &- 48)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  } else {
    let uppercaseUpperBound = 65 /* "A" */ &+ UInt8(radix &- 10)
    let lowercaseUpperBound = 97 /* "a" */ &+ UInt8(radix &- 10)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 /* "0" */ && digit < 58) {
        digitValue = Result(digit &- 48)
      } else if _fastPath(digit >= 65 && digit < uppercaseUpperBound) {
        digitValue = Result(digit &- 65 &+ 10)
      } else if _fastPath(digit >= 97 && digit < lowercaseUpperBound) {
        digitValue = Result(digit &- 97 &+ 10)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  }
  return result
}

@_alwaysEmitIntoClient
internal func _parseASCII<UTF8CodeUnits: Collection, Result: FixedWidthInteger>(
  _ codeUnits: UTF8CodeUnits, radix: Int
) -> Result? where UTF8CodeUnits.Element == UInt8 {
  _internalInvariant(!codeUnits.isEmpty)
  let first = codeUnits.first!
  if first == 45 /* "-" */ {
    return _parseASCIIDigits(
      codeUnits.dropFirst(), radix: radix, isNegative: true)
  }
  if first == 43 /* "+" */ {
    return _parseASCIIDigits(
      codeUnits.dropFirst(), radix: radix, isNegative: false)
  }
  return _parseASCIIDigits(codeUnits, radix: radix, isNegative: false)
}
<commit_msg>[stdlib] Never inline fallback helper methods when parsing strings to integers.<commit_after>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

// N.B.: This free function has been manually specialized below where
// `UTF8CodeUnits == UnsafeBufferPoint<UInt8>`. Ensure that any changes are
// made in sync.
@_alwaysEmitIntoClient
@inline(never)
internal func _parseASCIIDigits<
  UTF8CodeUnits: Collection, Result: FixedWidthInteger
>(
  _ codeUnits: UTF8CodeUnits, radix: Int, isNegative: Bool
) -> Result? where UTF8CodeUnits.Element == UInt8 {
  _internalInvariant(radix >= 2 && radix <= 36)
  guard _fastPath(!codeUnits.isEmpty) else { return nil }
  let multiplicand = Result(radix)
  var result = 0 as Result
  if radix <= 10 {
    let upperBound = 48 /* "0" */ &+ UInt8(radix)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 && digit < upperBound) {
        digitValue = Result(digit &- 48)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  } else {
    let uppercaseUpperBound = 65 /* "A" */ &+ UInt8(radix &- 10)
    let lowercaseUpperBound = 97 /* "a" */ &+ UInt8(radix &- 10)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 /* "0" */ && digit < 58) {
        digitValue = Result(digit &- 48)
      } else if _fastPath(digit >= 65 && digit < uppercaseUpperBound) {
        digitValue = Result(digit &- 65 &+ 10)
      } else if _fastPath(digit >= 97 && digit < lowercaseUpperBound) {
        digitValue = Result(digit &- 97 &+ 10)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  }
  return result
}

// N.B.: This free function is a manually specialized version of the function
// above. Ensure that any changes are made in sync.
@_alwaysEmitIntoClient
internal func _parseASCIIDigits<Result: FixedWidthInteger>(
  _ codeUnits: UnsafeBufferPointer<UInt8>, radix: Int, isNegative: Bool
) -> Result? {
  _internalInvariant(radix >= 2 && radix <= 36)
  guard _fastPath(!codeUnits.isEmpty) else { return nil }
  let multiplicand = Result(radix)
  var result = 0 as Result
  if radix <= 10 {
    let upperBound = 48 /* "0" */ &+ UInt8(radix)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 && digit < upperBound) {
        digitValue = Result(digit &- 48)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  } else {
    let uppercaseUpperBound = 65 /* "A" */ &+ UInt8(radix &- 10)
    let lowercaseUpperBound = 97 /* "a" */ &+ UInt8(radix &- 10)
    for digit in codeUnits {
      let digitValue: Result
      if _fastPath(digit >= 48 /* "0" */ && digit < 58) {
        digitValue = Result(digit &- 48)
      } else if _fastPath(digit >= 65 && digit < uppercaseUpperBound) {
        digitValue = Result(digit &- 65 &+ 10)
      } else if _fastPath(digit >= 97 && digit < lowercaseUpperBound) {
        digitValue = Result(digit &- 97 &+ 10)
      } else {
        return nil
      }
      let (temporary, overflow1) =
        result.multipliedReportingOverflow(by: multiplicand)
      guard _fastPath(!overflow1) else { return nil }
      let (nextResult, overflow2) = isNegative
        ? temporary.subtractingReportingOverflow(digitValue)
        : temporary.addingReportingOverflow(digitValue)
      guard _fastPath(!overflow2) else { return nil }
      result = nextResult
    }
  }
  return result
}

@_alwaysEmitIntoClient
@inline(never)
internal func _parseASCII<UTF8CodeUnits: Collection, Result: FixedWidthInteger>(
  _ codeUnits: UTF8CodeUnits, radix: Int
) -> Result? where UTF8CodeUnits.Element == UInt8 {
  _internalInvariant(!codeUnits.isEmpty)
  let first = codeUnits.first!
  if first == 45 /* "-" */ {
    return _parseASCIIDigits(
      codeUnits.dropFirst(), radix: radix, isNegative: true)
  }
  if first == 43 /* "+" */ {
    return _parseASCIIDigits(
      codeUnits.dropFirst(), radix: radix, isNegative: false)
  }
  return _parseASCIIDigits(codeUnits, radix: radix, isNegative: false)
}

{'fraction_non_alphanumeric': 0.13320707070707072, 'fraction_numerical': 0.022907647907647908, 'mean_word_length': 2.7211409395973156, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964778', 'n_tokens_mistral': 3521, 'n_tokens_neox': 3290, 'n_words': 908}