Optimizations and memory leak fixes

This commit is contained in:
CloneTrooper1019
2020-08-17 00:33:59 -05:00
parent 0ca6738cb9
commit 297426bdb5
20 changed files with 134 additions and 125 deletions

@ -41,7 +41,7 @@ namespace RobloxFiles
Region3int16,
}
public class Attribute
public class Attribute : IDisposable
{
public AttributeType DataType { get; private set; }
public object Value { get; private set; }
@ -202,7 +202,12 @@ namespace RobloxFiles
reader = null;
}
public void Dispose()
{
reader.Dispose();
}
internal Attribute(BinaryReader reader)
{
this.reader = reader;
@ -252,7 +257,7 @@ namespace RobloxFiles
internal byte[] Serialize()
{
// TODO
return new byte[0];
return Array.Empty<byte>();
}
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Reflection;
@ -66,7 +67,7 @@ namespace RobloxFiles
{
get
{
return Attributes?.Serialize() ?? new byte[0];
return Attributes?.Serialize() ?? Array.Empty<byte>();
}
set
{
@ -136,6 +137,7 @@ namespace RobloxFiles
/// <param name="ancestor">The instance whose ancestry will be tested against this Instance.</param>
public bool IsDescendantOf(Instance ancestor)
{
Contract.Requires(ancestor != null);
return ancestor.IsAncestorOf(this);
}
@ -265,7 +267,7 @@ namespace RobloxFiles
.Where(child => name == child.Name)
.Cast<T>();
if (query.Count() > 0)
if (query.Any())
{
result = query.First();
}
@ -309,7 +311,7 @@ namespace RobloxFiles
while (ancestor != null)
{
if (ancestor is T && ancestor.Name == name)
return (T)ancestor;
return ancestor as T;
ancestor = ancestor.Parent;
}
@ -334,15 +336,12 @@ namespace RobloxFiles
/// <param name="name">The Name of the Instance to find.</param>
public T FindFirstAncestorOfClass<T>() where T : Instance
{
Type classType = typeof(T);
string className = classType.Name;
Instance ancestor = Parent;
while (ancestor != null)
{
if (ancestor is T)
return (T)ancestor;
return ancestor as T;
ancestor = ancestor.Parent;
}
@ -387,7 +386,7 @@ namespace RobloxFiles
T result = null;
if (query.Count() > 0)
if (query.Any())
{
result = query.First();
}
@ -421,7 +420,7 @@ namespace RobloxFiles
T result = null;
if (query.Count() > 0)
if (query.Any())
{
result = query.First();
}

@ -152,7 +152,7 @@ namespace RobloxFiles
{
FieldInfo directField = instType
.GetFields()
.Where(field => field.Name.StartsWith(Name))
.Where(field => field.Name.StartsWith(Name, StringComparison.InvariantCulture))
.Where(field => field.DeclaringType == instType)
.FirstOrDefault();