Skip to content

Commit 21455e3

Browse files
author
Lance Parker
committed
use constants instead of ✨magic✨ numbers
1 parent 6ccbf72 commit 21455e3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

stdlib/public/core/StringNormalization.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ internal enum _Normalization {
3232
// musical notes). This expansion is capped by the maximum expansion factor of
3333
// the normal form. For NFC, that is 3x.
3434
internal static let _maxNFCExpansionFactor = 3
35+
internal static let _maxUTF16toUTF8ExpansionFactor = 3
3536
}
3637

3738
extension Unicode.Scalar {
@@ -117,9 +118,10 @@ internal enum NormalizationResult {
117118
}
118119

119120
static func bufferTooSmall(count: Int) -> NormalizationResult {
120-
let outputBufferSize = count * 9
121+
let outputBufferSize =
122+
count * _Normalization._maxNFCExpansionFactor * _Normalization._maxUTF16toUTF8ExpansionFactor
121123
let icuInputBufferSize = count
122-
let icuOutputBufferSize = count * 3
124+
let icuOutputBufferSize = count * _Normalization._maxNFCExpansionFactor
123125
let resizeRequest = BufferResizeRequest(
124126
outputBufferSize: outputBufferSize,
125127
icuInputBufferSize: icuInputBufferSize,

0 commit comments

Comments
 (0)