Skip to content

Commit 270fbf5

Browse files
authored
Optimize TranslateString() (#383)
1 parent b2f7435 commit 270fbf5

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

Orm/Xtensive.Orm/Caching/MfLruCache.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public virtual void CollectGarbage()
220220

221221
Exception error = null;
222222
int removedCount = 0;
223-
double effeciency = 0;
223+
double efficiency = 0;
224224
try {
225225
// Preparing arrays for selection
226226
var times = new int[count];
@@ -270,13 +270,13 @@ public virtual void CollectGarbage()
270270
if (efficiencyFactor<0)
271271
timeShift = -efficiencyFactor; // Constant timeShift is defined
272272
else {
273-
// Relative effeciency factor is defined
273+
// Relative efficiency factor is defined
274274
if (removedCount < 1)
275275
removedCount = 1;
276-
effeciency =
276+
efficiency =
277277
((double) GcOperationCost * removedCount + time) /
278278
((double) GcOperationCost * count + time);
279-
timeShift = ((int) Math.Ceiling(Math.Log(1 / effeciency, 2)));
279+
timeShift = ((int) Math.Ceiling(Math.Log(1 / efficiency, 2)));
280280
timeShift += efficiencyFactor;
281281
if (timeShift > 7)
282282
timeShift = 7;
@@ -296,7 +296,7 @@ public virtual void CollectGarbage()
296296
// Logging
297297
if (CoreLog.IsLogged(LogLevel.Debug)) {
298298
CoreLog.Debug("MfLruCache.CollectGarbage: removed: {0} from {1}, efficiency: {2}, time shift: {3}",
299-
removedCount, count, effeciency, timeShift);
299+
removedCount, count, efficiency, timeShift);
300300
if (error!=null)
301301
CoreLog.Debug(error, "Caught at MfLruCache.CollectGarbage");
302302
}

Orm/Xtensive.Orm/Core/InheritableScope.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected internal InheritableScope(TContext context)
3636
protected internal InheritableScope()
3737
: base(false)
3838
{
39-
// Must be replaced to more effecient check from the point of performance.
39+
// Must be replaced to more efficient check from the point of performance.
4040
//
4141
// var type = GetType();
4242
// if (allowedType==null) lock (@lock) if (allowedType==null)
@@ -61,4 +61,4 @@ static InheritableScope()
6161
Strings.ExOnlyOneAncestorOfEachInstanceOfThisGenericTypeIsAllowed);
6262
}
6363
}
64-
}
64+
}

Orm/Xtensive.Orm/Sql/Compiler/SqlTranslator.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,11 +2348,18 @@ public virtual void TranslateSortOrder(IOutput output, bool ascending) =>
23482348
/// <param name="str">The string.</param>
23492349
public virtual void TranslateString(IOutput output, string str)
23502350
{
2351-
// this is more effecient than SqlHelper.QuoteString()
2351+
// this is more efficient than SqlHelper.QuoteString()
23522352
_ = output.AppendLiteral('\'');
2353-
foreach (var ch in str) {
2354-
TranslateChar(output, ch);
2353+
2354+
if (str.ContainsAny(['\'', '\\', '\0'])) {
2355+
foreach (var ch in str) {
2356+
TranslateChar(output, ch);
2357+
}
23552358
}
2359+
else {
2360+
_ = output.AppendLiteral(str);
2361+
}
2362+
23562363
_ = output.AppendLiteral('\'');
23572364
}
23582365

@@ -2375,21 +2382,6 @@ protected virtual void TranslateChar(IOutput output, char ch)
23752382
}
23762383
}
23772384

2378-
protected virtual void TranslateStringChar(IOutput output, char ch)
2379-
{
2380-
switch (ch) {
2381-
case '\0':
2382-
break;
2383-
case '\'':
2384-
output.AppendLiteral("''");
2385-
break;
2386-
default:
2387-
output.AppendLiteral(ch);
2388-
break;
2389-
}
2390-
}
2391-
2392-
23932385
/// <summary>
23942386
/// Translates identifier names (one or several) and writes result to <paramref name="output"/>
23952387
/// </summary>

0 commit comments

Comments
 (0)