Skip to content

Commit a88955b

Browse files
committed
Fix SubList implementation in extensions
1 parent 81574c7 commit a88955b

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

itext/itext.io/itext/io/IOExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ source product.
4747
using System.IO;
4848
using System.Reflection;
4949
using System.Text;
50+
using iText.IO.Util.Collections;
5051

5152
namespace iText.IO {
5253
internal static class IOExtensions {
@@ -98,6 +99,13 @@ public static long Skip(this Stream s, long n) {
9899
}
99100

100101
public static List<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex) {
102+
if (list is SingletonList<T>) {
103+
if (fromIndex == 0 && toIndex >= 1) {
104+
return new List<T>(list);
105+
} else {
106+
return new List<T>();
107+
}
108+
}
101109
return ((List<T>) list).GetRange(fromIndex, toIndex - fromIndex);
102110
}
103111

itext/itext.kernel/KernelExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,17 @@ public static long Skip(this Stream s, long n) {
113113
return n;
114114
}
115115

116-
public static List<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex) {
117-
return ((List<T>) list).GetRange(fromIndex, toIndex - fromIndex);
118-
}
116+
public static List<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex) {
117+
if (list is SingletonList<T>) {
118+
if (fromIndex == 0 && toIndex >= 1) {
119+
return new List<T>(list);
120+
} else {
121+
return new List<T>();
122+
}
123+
}
124+
return ((List<T>) list).GetRange(fromIndex, toIndex - fromIndex);
125+
}
126+
119127

120128
public static void AddAll<T>(this IList<T> list, IEnumerable<T> c) {
121129
((List<T>) list).AddRange(c);

itext/itext.layout/itext/layout/LayoutExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,16 @@ public static TValue Put<TKey, TValue>(this IDictionary<TKey, TValue> col, TKey
172172
return oldVal;
173173
}
174174

175-
public static List<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex) {
176-
return ((List<T>) list).GetRange(fromIndex, toIndex - fromIndex);
177-
}
175+
public static List<T> SubList<T>(this IList<T> list, int fromIndex, int toIndex) {
176+
if (list is SingletonList<T>) {
177+
if (fromIndex == 0 && toIndex >= 1) {
178+
return new List<T>(list);
179+
} else {
180+
return new List<T>();
181+
}
182+
}
183+
return ((List<T>) list).GetRange(fromIndex, toIndex - fromIndex);
184+
}
178185

179186
public static String[] Split(this String str, String regex) {
180187
return str.Split(regex.ToCharArray());

0 commit comments

Comments
 (0)