mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
uses stringbuilder instead of alloc+concat for speed now
This commit is contained in:
parent
82fe1e10d9
commit
89e13334ae
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
namespace BinLogReader
|
||||
{
|
||||
@ -47,45 +48,52 @@ public static bool HasFlag(BinLogFlags a, BinLogFlags b)
|
||||
return ( (a & b) == b );
|
||||
}
|
||||
|
||||
public static string PluginText(Plugin pl, BinLogFlags flags)
|
||||
public static void PluginText(StringBuilder sb, Plugin pl, BinLogFlags flags)
|
||||
{
|
||||
string plugintext = "";
|
||||
if (HasFlag(flags, BinLogFlags.Show_PlugId)
|
||||
&& HasFlag(flags, BinLogFlags.Show_PlugFile))
|
||||
{
|
||||
plugintext = "\"" + pl.File + "\"" + " (" + pl.Index + ")";
|
||||
sb.Append("\"");
|
||||
sb.Append(pl.File);
|
||||
sb.Append("\"");
|
||||
sb.Append(" (");
|
||||
sb.Append(pl.Index);
|
||||
sb.Append(")");
|
||||
}
|
||||
else if (HasFlag(flags, BinLogFlags.Show_PlugId))
|
||||
{
|
||||
plugintext = pl.Index.ToString();
|
||||
sb.Append(pl.Index);
|
||||
}
|
||||
else if (HasFlag(flags, BinLogFlags.Show_PlugFile))
|
||||
{
|
||||
plugintext = "\"" + pl.File + "\"";
|
||||
sb.Append("\"");
|
||||
sb.Append(pl.File);
|
||||
sb.Append("\"");
|
||||
}
|
||||
return plugintext;
|
||||
}
|
||||
|
||||
public static string BinLogString(BinLogEntry ble, BinLogFlags flags)
|
||||
public static void BinLogString(StringBuilder sb, BinLogEntry ble, BinLogFlags flags)
|
||||
{
|
||||
string logtext = "";
|
||||
bool realtime = false;
|
||||
if (HasFlag(flags, BinLogFlags.Show_RealTime))
|
||||
logtext += ble.realtime.ToString();
|
||||
{
|
||||
sb.Append(ble.realtime.ToString());
|
||||
realtime = true;
|
||||
}
|
||||
if (HasFlag(flags, BinLogFlags.Show_GameTime))
|
||||
{
|
||||
if (logtext.Length > 0)
|
||||
if (realtime)
|
||||
{
|
||||
logtext += ", " + ble.gametime.ToString();
|
||||
sb.Append(", ");
|
||||
sb.Append(ble.gametime.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
logtext += ble.gametime.ToString();
|
||||
sb.Append(ble.gametime.ToString());
|
||||
}
|
||||
}
|
||||
logtext += ": ";
|
||||
logtext += ble.ToLogString(flags);
|
||||
|
||||
return logtext;
|
||||
sb.Append(": ");
|
||||
ble.ToLogString(sb, flags);
|
||||
}
|
||||
|
||||
public float gametime
|
||||
@ -116,7 +124,7 @@ public long realtime
|
||||
}
|
||||
|
||||
public abstract BinLogOp Op();
|
||||
public abstract string ToLogString(BinLogFlags flags);
|
||||
public abstract void ToLogString(StringBuilder sb, BinLogFlags flags);
|
||||
};
|
||||
|
||||
public class BinLogSetLine : BinLogEntry
|
||||
@ -137,12 +145,13 @@ public BinLogSetLine(int _line, float gt, long rt, Plugin _pl)
|
||||
line = _line;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugtext = BinLogEntry.PluginText(plugin, flags);
|
||||
string logtext = "Plugin hit line " + Line + ".";
|
||||
|
||||
return logtext;
|
||||
sb.Append("Plugin ");
|
||||
BinLogEntry.PluginText(sb, plugin, flags);
|
||||
sb.Append(" hit line ");
|
||||
sb.Append(Line);
|
||||
sb.Append(".");
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -169,13 +178,15 @@ public BinLogPublic(int pi, float gt, long rt, Plugin _pl)
|
||||
pubidx = pi;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugtext = BinLogEntry.PluginText(plugin, flags);
|
||||
string logtext = "Plugin " + plugtext + " had public function ";
|
||||
logtext += "\"" + Public + "\" (" + pubidx + ") called.";
|
||||
|
||||
return logtext;
|
||||
sb.Append("Plugin ");
|
||||
BinLogEntry.PluginText(sb, plugin, flags);
|
||||
sb.Append(" had public function \"");
|
||||
sb.Append(Public);
|
||||
sb.Append("\" (");
|
||||
sb.Append(pubidx);
|
||||
sb.Append(") called.");
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -198,13 +209,17 @@ public BinLogSetString(long addr, int _maxlen, string fmt, float gt, long rt, Pl
|
||||
text = fmt;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugtext = BinLogEntry.PluginText(plugin, flags);
|
||||
string logtext = "Setting string (addr " + address + ") (maxlen " + maxlen + ") from Plugin " + plugtext + ". String:";
|
||||
logtext += "\n\t " + text;
|
||||
|
||||
return logtext;
|
||||
sb.Append("Setting string (addr ");
|
||||
sb.Append(address);
|
||||
sb.Append(") (maxlen ");
|
||||
sb.Append(maxlen);
|
||||
sb.Append(") from Plugin ");
|
||||
BinLogEntry.PluginText(sb, plugin, flags);
|
||||
sb.Append(". String:");
|
||||
sb.Append("\n\t ");
|
||||
sb.Append(text);
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -225,13 +240,15 @@ public BinLogGetString(long addr, string fmt, float gt, long rt, Plugin _pl)
|
||||
text = fmt;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugtext = BinLogEntry.PluginText(plugin, flags);
|
||||
string logtext = "Retrieving string (addr " + address + ") from Plugin " + plugtext + ". String:";
|
||||
logtext += "\n\t " + text;
|
||||
|
||||
return logtext;
|
||||
sb.Append("Retrieving string (addr ");
|
||||
sb.AppendFormat("0x{0:X}", address);
|
||||
sb.Append(") from Plugin ");
|
||||
BinLogEntry.PluginText(sb, plugin, flags);
|
||||
sb.Append(". String:");
|
||||
sb.Append("\n\t ");
|
||||
sb.Append(text);
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -250,9 +267,10 @@ public BinLogNativeRet(long ret, float gt, long rt, Plugin _pl)
|
||||
returnval = ret;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
return "Native returned: " + returnval;
|
||||
sb.Append("Native returned: ");
|
||||
sb.Append(returnval);
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -281,14 +299,17 @@ public BinLogNativeCall(int na, int nu, float gt, long rt, Plugin _pl)
|
||||
numparams = nu;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugtext = BinLogEntry.PluginText(plugin, flags);
|
||||
string logtext = "Plugin " + plugtext + " called native ";
|
||||
logtext += "\"" + Native + "\" (" + nativeidx + ")";
|
||||
logtext += " with " + numparams + " parameters.";
|
||||
|
||||
return logtext;
|
||||
sb.Append("Plugin ");
|
||||
BinLogEntry.PluginText(sb, plugin, flags);
|
||||
sb.Append(" called native \"");
|
||||
sb.Append(Native);
|
||||
sb.Append("\" (");
|
||||
sb.Append(nativeidx);
|
||||
sb.Append(") with ");
|
||||
sb.Append(numparams);
|
||||
sb.Append(" parameters.");
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -306,25 +327,26 @@ public BinLogSimple(BinLogOp op, float gt, long rt, Plugin _pl) :
|
||||
my_op = op;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
switch (my_op)
|
||||
{
|
||||
case BinLogOp.BinLog_Start:
|
||||
{
|
||||
return "Binary log started.";
|
||||
sb.Append("Binary log started.");
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_End:
|
||||
{
|
||||
return "Binary log ended.";
|
||||
sb.Append("Binary log ended.");
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_Invalid:
|
||||
{
|
||||
return "Binary log corrupt past this point.";
|
||||
sb.Append("Binary log corrupt past this point.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public override BinLogOp Op()
|
||||
@ -359,21 +381,19 @@ public BinLogNativeParams(float gt, long rt, Plugin _pl)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string logtext = "Native parameters: (";
|
||||
sb.Append("Native parameters: (");
|
||||
if (plist != null)
|
||||
{
|
||||
for (int i=0; i<plist.Count; i++)
|
||||
{
|
||||
logtext += plist[i].ToString();
|
||||
sb.Append(plist[i].ToString());
|
||||
if (i < plist.Count - 1)
|
||||
logtext += ", ";
|
||||
sb.Append(", ");
|
||||
}
|
||||
}
|
||||
logtext += ")";
|
||||
|
||||
return logtext;
|
||||
sb.Append(")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,13 +416,16 @@ public BinLogFmtString(int pa, int ma, string str, float gt, long rt, Plugin _pl
|
||||
text = str;
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugintext = BinLogEntry.PluginText(pl, flags);
|
||||
string logtext = "Plugin " + plugintext + " formatted parameter " + parm;
|
||||
logtext += " (maxlen " + maxlen + "), result: \n\t" + text;
|
||||
|
||||
return logtext;
|
||||
sb.Append("Plugin ");
|
||||
BinLogEntry.PluginText(sb, pl, flags);
|
||||
sb.Append(" formatted parameter ");
|
||||
sb.Append(parm);
|
||||
sb.Append(" (maxlen ");
|
||||
sb.Append(maxlen);
|
||||
sb.Append("), result: \n\t");
|
||||
sb.Append(text);
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,13 +462,15 @@ public string version
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToLogString(BinLogFlags flags)
|
||||
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
||||
{
|
||||
string plugintext = BinLogEntry.PluginText(pl, flags);
|
||||
string logtext = "Plugin " + plugintext + " registered as ";
|
||||
logtext += "(\"" + _title + "\", \"" + _version + "\")";
|
||||
|
||||
return logtext;
|
||||
sb.Append("Plugin ");
|
||||
BinLogEntry.PluginText(sb, pl, flags);
|
||||
sb.Append(" registered as (\"");
|
||||
sb.Append(_title);
|
||||
sb.Append("\", \"");
|
||||
sb.Append(_version);
|
||||
sb.Append("\")");
|
||||
}
|
||||
|
||||
public BinLogRegister(float gt, long rt, Plugin _pl) :
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BinLogReader
|
||||
@ -309,15 +310,15 @@ private void UpdateViews(ViewAreas v, BinLogFlags b)
|
||||
{
|
||||
ArrayList al = binlog.OpList;
|
||||
BinLogEntry ble;
|
||||
string fulltext = "";
|
||||
StringBuilder sb = new StringBuilder(al.Count * 10);
|
||||
BinLogFlags flags = (BinLogFlags.Show_GameTime | BinLogFlags.Show_PlugFile | BinLogFlags.Show_PlugId);
|
||||
for (int i=0; i<al.Count; i++)
|
||||
{
|
||||
ble = (BinLogEntry)al[i];
|
||||
fulltext += BinLogEntry.BinLogString(ble,
|
||||
(BinLogFlags.Show_GameTime | BinLogFlags.Show_PlugFile | BinLogFlags.Show_PlugId));
|
||||
fulltext += "\n";
|
||||
BinLogEntry.BinLogString(sb, ble, flags);
|
||||
sb.Append("\n");
|
||||
}
|
||||
TextLog.Text = fulltext;
|
||||
TextLog.Text = sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user