Skip to content

Optimize TranslateString() #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Orm/Xtensive.Orm/Caching/MfLruCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public virtual void CollectGarbage()

Exception error = null;
int removedCount = 0;
double effeciency = 0;
double efficiency = 0;
try {
// Preparing arrays for selection
var times = new int[count];
Expand Down Expand Up @@ -270,13 +270,13 @@ public virtual void CollectGarbage()
if (efficiencyFactor<0)
timeShift = -efficiencyFactor; // Constant timeShift is defined
else {
// Relative effeciency factor is defined
// Relative efficiency factor is defined
if (removedCount < 1)
removedCount = 1;
effeciency =
efficiency =
((double) GcOperationCost * removedCount + time) /
((double) GcOperationCost * count + time);
timeShift = ((int) Math.Ceiling(Math.Log(1 / effeciency, 2)));
timeShift = ((int) Math.Ceiling(Math.Log(1 / efficiency, 2)));
timeShift += efficiencyFactor;
if (timeShift > 7)
timeShift = 7;
Expand All @@ -296,7 +296,7 @@ public virtual void CollectGarbage()
// Logging
if (CoreLog.IsLogged(LogLevel.Debug)) {
CoreLog.Debug("MfLruCache.CollectGarbage: removed: {0} from {1}, efficiency: {2}, time shift: {3}",
removedCount, count, effeciency, timeShift);
removedCount, count, efficiency, timeShift);
if (error!=null)
CoreLog.Debug(error, "Caught at MfLruCache.CollectGarbage");
}
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Core/InheritableScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected internal InheritableScope(TContext context)
protected internal InheritableScope()
: base(false)
{
// Must be replaced to more effecient check from the point of performance.
// Must be replaced to more efficient check from the point of performance.
//
// var type = GetType();
// if (allowedType==null) lock (@lock) if (allowedType==null)
Expand All @@ -61,4 +61,4 @@ static InheritableScope()
Strings.ExOnlyOneAncestorOfEachInstanceOfThisGenericTypeIsAllowed);
}
}
}
}
28 changes: 10 additions & 18 deletions Orm/Xtensive.Orm/Sql/Compiler/SqlTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,11 +2348,18 @@ public virtual void TranslateSortOrder(IOutput output, bool ascending) =>
/// <param name="str">The string.</param>
public virtual void TranslateString(IOutput output, string str)
{
// this is more effecient than SqlHelper.QuoteString()
// this is more efficient than SqlHelper.QuoteString()
_ = output.AppendLiteral('\'');
foreach (var ch in str) {
TranslateChar(output, ch);

if (str.ContainsAny(['\'', '\\', '\0'])) {
foreach (var ch in str) {
TranslateChar(output, ch);
}
}
else {
_ = output.AppendLiteral(str);
}

_ = output.AppendLiteral('\'');
}

Expand All @@ -2375,21 +2382,6 @@ protected virtual void TranslateChar(IOutput output, char ch)
}
}

protected virtual void TranslateStringChar(IOutput output, char ch)
{
switch (ch) {
case '\0':
break;
case '\'':
output.AppendLiteral("''");
break;
default:
output.AppendLiteral(ch);
break;
}
}


/// <summary>
/// Translates identifier names (one or several) and writes result to <paramref name="output"/>
/// </summary>
Expand Down