File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
src/ImageSharp/Metadata/Profiles/Exif Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 77using System . Diagnostics ;
88using System . Globalization ;
99using System . Runtime . CompilerServices ;
10+ using System . Runtime . InteropServices ;
1011using System . Text ;
1112using SixLabors . ImageSharp . Memory ;
1213
@@ -187,18 +188,22 @@ protected void ReadValues(List<IExifValue> values, uint offset)
187188
188189 protected void ReadSubIfd ( List < IExifValue > values )
189190 {
190- if ( this . subIfds is not null )
191+ if ( this . subIfds != null )
191192 {
192- do
193+ const int maxSubIfds = 8 ;
194+ const int maxNestingLevel = 8 ;
195+ Span < ulong > buf = stackalloc ulong [ maxSubIfds ] ;
196+ for ( int i = 0 ; i < maxNestingLevel && this . subIfds . Count > 0 ; i ++ )
193197 {
194- ulong [ ] buf = [ .. this . subIfds ] ;
198+ int sz = Math . Min ( this . subIfds . Count , maxSubIfds ) ;
199+ CollectionsMarshal . AsSpan ( this . subIfds ) [ ..sz ] . CopyTo ( buf ) ;
200+
195201 this . subIfds . Clear ( ) ;
196- foreach ( ulong subIfdOffset in buf )
202+ foreach ( ulong subIfdOffset in buf [ .. sz ] )
197203 {
198204 this . ReadValues ( values , ( uint ) subIfdOffset ) ;
199205 }
200206 }
201- while ( this . subIfds . Count > 0 ) ;
202207 }
203208 }
204209
You can’t perform that action at this time.
0 commit comments