Skip to content

Commit

Permalink
[Bind] Sort core functions before extensions
Browse files Browse the repository at this point in the history
Core functions are used more often than extensions. By grouping all
core functions to the front of the address table, and all extensions by
their extension category, we improve the chances of a cache hit.
  • Loading branch information
thefiddler committed May 31, 2014
1 parent e8abe05 commit e00add6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 3 additions & 6 deletions Source/Bind/CSharpSpecWriter.cs
Expand Up @@ -197,11 +197,9 @@ void WriteClasses(BindStreamWriter sw, ClassCollection classes, EnumCollection e
{
Trace.WriteLine(String.Format("Writing wrappers to:\t{0}.{1}", Settings.OutputNamespace, Settings.OutputClass));

// Sort delegates by extension and by name
var delegates_sorted = delegates.Values
.Select(d => d.First())
.OrderBy(d => d.Extension)
.ThenBy(d => d.Name);
.OrderBy(d => d);

sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute
sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
Expand All @@ -225,7 +223,7 @@ void WriteClasses(BindStreamWriter sw, ClassCollection classes, EnumCollection e
sw.WriteLine("EntryPointNames = new byte[]", delegates.Count);
sw.WriteLine("{");
sw.Indent();
foreach (var d in delegates.Values.Select(d => d.First()).OrderBy(d => d.Name))
foreach (var d in delegates_sorted)
{
if (d.RequiresSlot(Settings))
{
Expand All @@ -243,7 +241,7 @@ void WriteClasses(BindStreamWriter sw, ClassCollection classes, EnumCollection e
sw.WriteLine("{");
sw.Indent();
int offset = 0;
foreach (var d in delegates.Values.Select(d => d.First()).OrderBy(d => d.Name))
foreach (var d in delegates_sorted)
{
if (d.RequiresSlot(Settings))
{
Expand Down Expand Up @@ -295,7 +293,6 @@ void WriteClasses(BindStreamWriter sw, ClassCollection classes, EnumCollection e
// Emit native signatures.
// These are required by the patcher.
int current_signature = 0;
//foreach (var d in wrappers.OrderBy(w => w.Key).Select(w => w.Value).SelectMany(e => e).Select(w => w.WrappedDelegate).Distinct().OrderBy(d => d))
foreach (var d in delegates_sorted)
{
sw.WriteLine("[Slot({0})]", d.Slot);
Expand Down
3 changes: 1 addition & 2 deletions Source/Bind/FuncProcessor.cs
Expand Up @@ -199,8 +199,7 @@ void GenerateAddressTable(DelegateCollection delegates)
// Todo: it would be best to allocate slots for core functions first

int slot = -1;
foreach (var list in delegates.Values
.OrderBy(d => d.First().Name))
foreach (var list in delegates.Values.OrderBy(d => d.First()))
{
var func = list.First();
if (func.RequiresSlot(Settings))
Expand Down
6 changes: 5 additions & 1 deletion Source/Bind/Structures/Delegate.cs
Expand Up @@ -277,7 +277,11 @@ override public string ToString()

public int CompareTo(Delegate other)
{
int ret = Name.CompareTo(other.Name);
int ret = (Extension != "Core").CompareTo(other.Extension != "Core");
if (ret == 0)
ret = Extension.CompareTo(other.Extension);
if (ret == 0)
ret = Name.CompareTo(other.Name);
if (ret == 0)
ret = Parameters.CompareTo(other.Parameters);
if (ret == 0)
Expand Down

0 comments on commit e00add6

Please sign in to comment.