Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up sheet range calculation #72

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/Lumina/Excel/LazyRow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Lumina.Data;
using Lumina.Data.Files.Excel;
Expand Down Expand Up @@ -28,7 +29,7 @@ public interface ILazyRow

public class EmptyLazyRow : ILazyRow
{
private static readonly ExcelDataPagination _blankPagination = new();
private static readonly Dictionary< string, List<Range> > _ranges = new();

public uint Row { get; set; }
public bool IsValueCreated => false;
Expand All @@ -49,19 +50,23 @@ public static ILazyRow GetFirstLazyRowOrEmpty( GameData gameData, uint row, Lang
{
foreach( var sheetName in sheetNames )
{
var exh = gameData.GetFile<ExcelHeaderFile>( $"exd/{sheetName}.exh" );
if( exh == null )
if( !_ranges.ContainsKey( sheetName ) )
{
continue;
var exh = gameData.GetFile< ExcelHeaderFile >( $"exd/{sheetName}.exh" );
if( exh == null )
{
continue;
}
_ranges.Add( sheetName, exh.DataPages.Select( p => new Range( (int)p.StartId, (int) (p.StartId + p.RowCount) ) ).ToList() );
}

var page = exh.DataPages.FirstOrDefault( s => row >= s.StartId && row <= s.StartId + s.RowCount, _blankPagination );
if( page.Equals( _blankPagination ) )

foreach( var range in _ranges[sheetName] )
{
continue;
}

return new LazyRow<ExcelRow>(gameData, row, language);
if (row < range.Start.Value && row > range.End.Value)
{
return new LazyRow< ExcelRow >( gameData, row, language );
}
}
}
return new EmptyLazyRow( row );
}
Expand Down
Loading