Skip to content

Commit

Permalink
#586 bitmap loader init perf fixes (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvreony committed Oct 1, 2020
1 parent de3466d commit 92b41f9
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Graphics;
Expand Down Expand Up @@ -129,32 +130,42 @@ public IBitmap Create(float width, float height)
{
// VS2019 onward
var drawableTypes = assemblies
.AsParallel()
.SelectMany(a => GetTypesFromAssembly(a, log))
.Where(x => x.Name == "Resource" && x.GetNestedType("Drawable") != null)
.Where(x => x.Name.Equals("Resource", StringComparison.Ordinal) && x.GetNestedType("Drawable") != null)
.Select(x => x.GetNestedType("Drawable"))
.ToArray();

if (log != null)
if (log?.IsDebugEnabled == true)
{
log.Debug(() => "DrawableList. Got " + drawableTypes.Length + " types.");
var output = new StringBuilder();
output.Append("DrawableList. Got ").Append(drawableTypes.Length).AppendLine(" types.");

foreach (var drawableType in drawableTypes)
{
log.Debug(() => "DrawableList Type: " + drawableType.Name);
output.Append("DrawableList Type: ").AppendLine(drawableType.Name);
}

log.Debug(output.ToString());
}

var result = drawableTypes
.AsParallel()
.SelectMany(x => x.GetFields())
.Where(x => x.FieldType == typeof(int) && x.IsLiteral)
.ToDictionary(k => k.Name, v => (int)v.GetRawConstantValue());

if (log != null)
if (log?.IsDebugEnabled == true)
{
log.Debug(() => "DrawableList. Got " + result.Count + " items.");
var output = new StringBuilder();
output.Append("DrawableList. Got ").Append(result.Count).AppendLine(" items.");

foreach (var keyValuePair in result)
{
log.Debug(() => "DrawableList Item: " + keyValuePair.Key);
output.Append("DrawableList Item: ").AppendLine(keyValuePair.Key);
}

log.Debug(output.ToString());
}

return result;
Expand Down

0 comments on commit 92b41f9

Please sign in to comment.