mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-25 03:25:13 +00:00
Strings should not be concatenated using '+' in a loop (#5664)
* Strings should not be concatenated using '+' in a loop * fix IDE0090 * undo GenerateLoadOrStore * prefer string interpolation * Update src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs Co-authored-by: Mary <thog@protonmail.com> --------- Co-authored-by: Mary <thog@protonmail.com>
This commit is contained in:
parent
0aceb534cb
commit
7835968214
12 changed files with 62 additions and 51 deletions
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace ARMeilleure.Diagnostics
|
||||
{
|
||||
|
@ -48,14 +49,15 @@ namespace ARMeilleure.Diagnostics
|
|||
ulong diff = address - symbol.Start;
|
||||
ulong rem = diff % symbol.ElementSize;
|
||||
|
||||
result = symbol.Name + "_" + diff / symbol.ElementSize;
|
||||
StringBuilder resultBuilder = new();
|
||||
resultBuilder.Append($"{symbol.Name}_{diff / symbol.ElementSize}");
|
||||
|
||||
if (rem != 0)
|
||||
{
|
||||
result += "+" + rem;
|
||||
resultBuilder.Append($"+{rem}");
|
||||
}
|
||||
|
||||
_symbols.TryAdd(address, result);
|
||||
_symbols.TryAdd(address, resultBuilder.ToString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -327,7 +327,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
|
||||
string imageUrl = _amiiboList.Find(amiibo => amiibo.Equals(selected)).Image;
|
||||
|
||||
string usageString = "";
|
||||
StringBuilder usageStringBuilder = new();
|
||||
|
||||
for (int i = 0; i < _amiiboList.Count; i++)
|
||||
{
|
||||
|
@ -341,20 +341,19 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
{
|
||||
foreach (AmiiboApiUsage usageItem in item.AmiiboUsage)
|
||||
{
|
||||
usageString += Environment.NewLine +
|
||||
$"- {usageItem.Usage.Replace("/", Environment.NewLine + "-")}";
|
||||
usageStringBuilder.Append($"{Environment.NewLine}- {usageItem.Usage.Replace("/", Environment.NewLine + "-")}");
|
||||
|
||||
writable = usageItem.Write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (usageString.Length == 0)
|
||||
if (usageStringBuilder.Length == 0)
|
||||
{
|
||||
usageString = LocaleManager.Instance[LocaleKeys.Unknown] + ".";
|
||||
usageStringBuilder.Append($"{LocaleManager.Instance[LocaleKeys.Unknown]}.");
|
||||
}
|
||||
|
||||
Usage = $"{LocaleManager.Instance[LocaleKeys.Usage]} {(writable ? $" ({LocaleManager.Instance[LocaleKeys.Writable]})" : "")} : {usageString}";
|
||||
Usage = $"{LocaleManager.Instance[LocaleKeys.Usage]} {(writable ? $" ({LocaleManager.Instance[LocaleKeys.Writable]})" : "")} : {usageStringBuilder}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,14 +92,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
private static string GetIndentation(int level)
|
||||
{
|
||||
string indentation = string.Empty;
|
||||
StringBuilder indentationBuilder = new();
|
||||
|
||||
for (int index = 0; index < level; index++)
|
||||
{
|
||||
indentation += Tab;
|
||||
indentationBuilder.Append(Tab);
|
||||
}
|
||||
|
||||
return indentation;
|
||||
return indentationBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|||
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenBallot;
|
||||
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenCall;
|
||||
|
@ -67,11 +68,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
int arity = (int)(info.Type & InstType.ArityMask);
|
||||
|
||||
string args = string.Empty;
|
||||
StringBuilder builder = new();
|
||||
|
||||
if (atomic && (operation.StorageKind == StorageKind.StorageBuffer || operation.StorageKind == StorageKind.SharedMemory))
|
||||
{
|
||||
args = GenerateLoadOrStore(context, operation, isStore: false);
|
||||
builder.Append(GenerateLoadOrStore(context, operation, isStore: false));
|
||||
|
||||
AggregateType dstType = operation.Inst == Instruction.AtomicMaxS32 || operation.Inst == Instruction.AtomicMinS32
|
||||
? AggregateType.S32
|
||||
|
@ -79,7 +80,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
for (int argIndex = operation.SourcesCount - arity + 2; argIndex < operation.SourcesCount; argIndex++)
|
||||
{
|
||||
args += ", " + GetSoureExpr(context, operation.GetSource(argIndex), dstType);
|
||||
builder.Append($", {GetSoureExpr(context, operation.GetSource(argIndex), dstType)}");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -88,16 +89,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
{
|
||||
if (argIndex != 0)
|
||||
{
|
||||
args += ", ";
|
||||
builder.Append(", ");
|
||||
}
|
||||
|
||||
AggregateType dstType = GetSrcVarType(inst, argIndex);
|
||||
|
||||
args += GetSoureExpr(context, operation.GetSource(argIndex), dstType);
|
||||
builder.Append(GetSoureExpr(context, operation.GetSource(argIndex), dstType));
|
||||
}
|
||||
}
|
||||
|
||||
return info.OpName + '(' + args + ')';
|
||||
return $"{info.OpName}({builder})";
|
||||
}
|
||||
else if ((info.Type & InstType.Op) != 0)
|
||||
{
|
||||
|
|
|
@ -779,17 +779,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
private static string GetMaskMultiDest(int mask)
|
||||
{
|
||||
string swizzle = ".";
|
||||
StringBuilder swizzleBuilder = new();
|
||||
swizzleBuilder.Append('.');
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if ((mask & (1 << i)) != 0)
|
||||
{
|
||||
swizzle += "xyzw"[i];
|
||||
swizzleBuilder.Append("xyzw"[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return swizzle;
|
||||
return swizzleBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
|
@ -785,30 +786,31 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|||
|
||||
private static string GetFunctionName(Operation baseOp, bool isMultiTarget, IReadOnlyList<uint> targetCbs)
|
||||
{
|
||||
string name = baseOp.Inst.ToString();
|
||||
StringBuilder nameBuilder = new();
|
||||
nameBuilder.Append(baseOp.Inst.ToString());
|
||||
|
||||
name += baseOp.StorageKind switch
|
||||
nameBuilder.Append(baseOp.StorageKind switch
|
||||
{
|
||||
StorageKind.GlobalMemoryS8 => "S8",
|
||||
StorageKind.GlobalMemoryS16 => "S16",
|
||||
StorageKind.GlobalMemoryU8 => "U8",
|
||||
StorageKind.GlobalMemoryU16 => "U16",
|
||||
_ => string.Empty,
|
||||
};
|
||||
});
|
||||
|
||||
if (isMultiTarget)
|
||||
{
|
||||
name += "Multi";
|
||||
nameBuilder.Append("Multi");
|
||||
}
|
||||
|
||||
foreach (uint targetCb in targetCbs)
|
||||
{
|
||||
(int sbCbSlot, int sbCbOffset) = UnpackCbSlotAndOffset(targetCb);
|
||||
|
||||
name += $"_c{sbCbSlot}o{sbCbOffset}";
|
||||
nameBuilder.Append($"_c{sbCbSlot}o{sbCbOffset}");
|
||||
}
|
||||
|
||||
return name;
|
||||
return nameBuilder.ToString();
|
||||
}
|
||||
|
||||
private static bool TryGenerateStorageOp(
|
||||
|
|
|
@ -19,6 +19,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Ryujinx.HLE.FileSystem
|
||||
|
@ -817,13 +818,13 @@ namespace Ryujinx.HLE.FileSystem
|
|||
|
||||
if (updateNcas.Count > 0)
|
||||
{
|
||||
string extraNcas = string.Empty;
|
||||
StringBuilder extraNcas = new();
|
||||
|
||||
foreach (var entry in updateNcas)
|
||||
{
|
||||
foreach (var (type, path) in entry.Value)
|
||||
{
|
||||
extraNcas += path + Environment.NewLine;
|
||||
extraNcas.AppendLine(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -954,13 +955,13 @@ namespace Ryujinx.HLE.FileSystem
|
|||
|
||||
if (updateNcas.Count > 0)
|
||||
{
|
||||
string extraNcas = string.Empty;
|
||||
StringBuilder extraNcas = new();
|
||||
|
||||
foreach (var entry in updateNcas)
|
||||
{
|
||||
foreach (var (type, path) in entry.Value)
|
||||
{
|
||||
extraNcas += path + Environment.NewLine;
|
||||
extraNcas.AppendLine(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -436,14 +436,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
uint nameIndex = sym.NameOffset;
|
||||
|
||||
string name = string.Empty;
|
||||
StringBuilder nameBuilder = new();
|
||||
|
||||
for (int chr; (chr = memory.Read<byte>(strTblAddr + nameIndex++)) != 0;)
|
||||
{
|
||||
name += (char)chr;
|
||||
nameBuilder.Append((char)chr);
|
||||
}
|
||||
|
||||
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||
return new ElfSymbol(nameBuilder.ToString(), sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||
}
|
||||
|
||||
private static ElfSymbol GetSymbol32(IVirtualMemoryManager memory, ulong address, ulong strTblAddr)
|
||||
|
@ -452,14 +452,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
uint nameIndex = sym.NameOffset;
|
||||
|
||||
string name = string.Empty;
|
||||
StringBuilder nameBuilder = new();
|
||||
|
||||
for (int chr; (chr = memory.Read<byte>(strTblAddr + nameIndex++)) != 0;)
|
||||
{
|
||||
name += (char)chr;
|
||||
nameBuilder.Append((char)chr);
|
||||
}
|
||||
|
||||
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||
return new ElfSymbol(nameBuilder.ToString(), sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sm
|
||||
{
|
||||
|
@ -235,7 +236,7 @@ namespace Ryujinx.HLE.HOS.Services.Sm
|
|||
|
||||
private static string ReadName(ServiceCtx context)
|
||||
{
|
||||
string name = string.Empty;
|
||||
StringBuilder nameBuilder = new();
|
||||
|
||||
for (int index = 0; index < 8 &&
|
||||
context.RequestData.BaseStream.Position <
|
||||
|
@ -245,11 +246,11 @@ namespace Ryujinx.HLE.HOS.Services.Sm
|
|||
|
||||
if (chr >= 0x20 && chr < 0x7f)
|
||||
{
|
||||
name += (char)chr;
|
||||
nameBuilder.Append((char)chr);
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
return nameBuilder.ToString();
|
||||
}
|
||||
|
||||
public override void DestroyAtExit()
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
|
|||
// OpenDisplay(nn::vi::DisplayName) -> u64 display_id
|
||||
public ResultCode OpenDisplay(ServiceCtx context)
|
||||
{
|
||||
string name = "";
|
||||
StringBuilder nameBuilder = new();
|
||||
|
||||
for (int index = 0; index < 8 && context.RequestData.BaseStream.Position < context.RequestData.BaseStream.Length; index++)
|
||||
{
|
||||
|
@ -150,11 +150,11 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
|
|||
|
||||
if (chr >= 0x20 && chr < 0x7f)
|
||||
{
|
||||
name += (char)chr;
|
||||
nameBuilder.Append((char)chr);
|
||||
}
|
||||
}
|
||||
|
||||
return OpenDisplayImpl(context, name);
|
||||
return OpenDisplayImpl(context, nameBuilder.ToString());
|
||||
}
|
||||
|
||||
[CommandCmif(1011)]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Horizon.Sdk.Sm
|
||||
{
|
||||
|
@ -78,7 +79,7 @@ namespace Ryujinx.Horizon.Sdk.Sm
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
string name = string.Empty;
|
||||
StringBuilder nameBuilder = new();
|
||||
|
||||
for (int index = 0; index < sizeof(ulong); index++)
|
||||
{
|
||||
|
@ -89,10 +90,10 @@ namespace Ryujinx.Horizon.Sdk.Sm
|
|||
break;
|
||||
}
|
||||
|
||||
name += (char)character;
|
||||
nameBuilder.Append((char)character);
|
||||
}
|
||||
|
||||
return name;
|
||||
return nameBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Ui.LocaleGenerator
|
||||
{
|
||||
|
@ -15,15 +16,17 @@ namespace Ryujinx.Ui.LocaleGenerator
|
|||
context.RegisterSourceOutput(contents, (spc, content) =>
|
||||
{
|
||||
var lines = content.Split('\n').Where(x => x.Trim().StartsWith("\"")).Select(x => x.Split(':')[0].Trim().Replace("\"", ""));
|
||||
string enumSource = "namespace Ryujinx.Ava.Common.Locale;\n";
|
||||
enumSource += "internal enum LocaleKeys\n{\n";
|
||||
StringBuilder enumSourceBuilder = new();
|
||||
enumSourceBuilder.AppendLine("namespace Ryujinx.Ava.Common.Locale;");
|
||||
enumSourceBuilder.AppendLine("internal enum LocaleKeys");
|
||||
enumSourceBuilder.AppendLine("{");
|
||||
foreach (var line in lines)
|
||||
{
|
||||
enumSource += $" {line},\n";
|
||||
enumSourceBuilder.AppendLine($" {line},");
|
||||
}
|
||||
enumSource += "}\n";
|
||||
enumSourceBuilder.AppendLine("}");
|
||||
|
||||
spc.AddSource("LocaleKeys", enumSource);
|
||||
spc.AddSource("LocaleKeys", enumSourceBuilder.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue