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 7
7
using System . Diagnostics ;
8
8
using System . Globalization ;
9
9
using System . Runtime . CompilerServices ;
10
+ using System . Runtime . InteropServices ;
10
11
using System . Text ;
11
12
using SixLabors . ImageSharp . Memory ;
12
13
@@ -187,18 +188,22 @@ protected void ReadValues(List<IExifValue> values, uint offset)
187
188
188
189
protected void ReadSubIfd ( List < IExifValue > values )
189
190
{
190
- if ( this . subIfds is not null )
191
+ if ( this . subIfds != null )
191
192
{
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 ++ )
193
197
{
194
- ulong [ ] buf = [ .. this . subIfds ] ;
198
+ int sz = Math . Min ( this . subIfds . Count , maxSubIfds ) ;
199
+ CollectionsMarshal . AsSpan ( this . subIfds ) [ ..sz ] . CopyTo ( buf ) ;
200
+
195
201
this . subIfds . Clear ( ) ;
196
- foreach ( ulong subIfdOffset in buf )
202
+ foreach ( ulong subIfdOffset in buf [ .. sz ] )
197
203
{
198
204
this . ReadValues ( values , ( uint ) subIfdOffset ) ;
199
205
}
200
206
}
201
- while ( this . subIfds . Count > 0 ) ;
202
207
}
203
208
}
204
209
You can’t perform that action at this time.
0 commit comments