Skip to content

Commit 822b1a2

Browse files
committed
Removed necessity to count twice and allocate similar string
1 parent 842ff23 commit 822b1a2

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/FirebirdSql.Data.FirebirdClient/Client/Managed/Version10/GdsStatement.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,13 +1786,9 @@ private static string TruncateStringByRuneCount(string s, DbField field)
17861786
return s;
17871787
}
17881788

1789-
var runeCount = s.CountRunes();
1790-
if (runeCount <= field.CharCount)
1791-
{
1792-
return s;
1793-
}
1789+
var truncated = s.TruncateStringToRuneCount(field.CharCount);
17941790

1795-
return new string(s.TruncateStringToRuneCount(field.CharCount));
1791+
return truncated == s.AsSpan() ? s : new string(truncated);
17961792
}
17971793

17981794
#endregion

src/FirebirdSql.Data.FirebirdClient/Common/DbField.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ public void SetValue(byte[] buffer)
327327
var s = Charset.GetString(buffer, 0, buffer.Length);
328328
if((Length % Charset.BytesPerCharacter) == 0)
329329
{
330-
var runes = s.CountRunes();
331-
if(runes > CharCount) {
332-
s = new string(s.TruncateStringToRuneCount(CharCount));
330+
var truncated = s.TruncateStringToRuneCount(CharCount);
331+
if(s.AsSpan() != truncated) {
332+
s = new string(truncated);
333333
}
334334
}
335335

0 commit comments

Comments
 (0)