Преглед изворни кода

SMB1: Minor optimization of GetFindInformationList

Tal Aloni пре 7 година
родитељ
комит
6c08f23751
1 измењених фајлова са 8 додато и 3 уклоњено
  1. 8 3
      SMBLibrary/Server/SMB1/SMB1FileStoreHelper.QueryDirectory.cs

+ 8 - 3
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.QueryDirectory.cs

@@ -50,13 +50,18 @@ namespace SMBLibrary.Server.SMB1
         public static FindInformationList GetFindInformationList(List<QueryDirectoryFileInformation> entries, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys, int maxLength)
         {
             FindInformationList result = new FindInformationList();
+            int pageLength = 0;
             for (int index = 0; index < entries.Count; index++)
             {
                 FindInformation infoEntry = GetFindInformation(entries[index], informationLevel, isUnicode, returnResumeKeys);
-                result.Add(infoEntry);
-                if (result.GetLength(isUnicode) > maxLength)
+                int entryLength = infoEntry.GetLength(isUnicode);
+                if (pageLength + entryLength <= maxLength)
+                {
+                    result.Add(infoEntry);
+                    pageLength += entryLength;
+                }
+                else
                 {
-                    result.RemoveAt(result.Count - 1);
                     break;
                 }
             }