History

GSF.Core: Modified IsamDataFileBase.WriteToDisk to write all records sequentially to the stream rather than seeking between each write operation.

StephenCWills committed 13 years ago

Commit 595894f1 parent 0eacf261 file · +15 −10Browse files

Unified · Split

Source/Libraries/GSF.Core/IO/IsamDataFileBase.cs+15−10
@@ -1269,13 +1269,11 @@ namespace GSF.IO · 1268 unmodified lines
12691269 if ((object)record != null)
12701270 {
12711271 int lastRecordIndex = (object)m_fileRecords == null ? RecordsOnDisk : RecordsInMemory;
1272− if (recordIndex > lastRecordIndex + 1)
1272+
1273+ // Write missing intermediate records.
1274+ for (int i = lastRecordIndex + 1; i < recordIndex; i++)
12731275 {
1274− // Write missing intermediate records.
1275− for (int i = lastRecordIndex + 1; i < recordIndex; i++)
1276− {
1277− Write(i, CreateNewRecord(i));
1278− }
1276+ Write(i, CreateNewRecord(i));
12791277 }
12801278
12811279 if ((object)m_fileRecords == null)
@@ -1287,6 +1285,7 @@ namespace GSF.IO · 5 unmodified lines
12871285 {
12881286 // Update in-memory record list.
12891287 lastRecordIndex = RecordsInMemory;
1288+
12901289 if (recordIndex == lastRecordIndex + 1)
12911290 {
12921291 // Add new record.
@@ -1491,17 +1490,23 @@ namespace GSF.IO · 198 unmodified lines
14911490 private void WriteToDisk(IEnumerable<T> records)
14921491 {
14931492 // Write all records to disk.
1494− int index = 0;
1493+ int count = 0;
14951494
1496− foreach (T item in records)
1495+ lock (m_fileData)
14971496 {
1498− WriteToDisk(++index, item);
1497+ m_fileData.Seek(0L, SeekOrigin.Begin);
1498+
1499+ foreach (T item in records)
1500+ {
1501+ item.CopyBinaryImageToStream(m_fileData);
1502+ count++;
1503+ }
14991504 }
15001505
15011506 // Discard previously existing records that were not written.
15021507 lock (m_fileData)
15031508 {
1504− m_fileData.SetLength(index * m_recordBuffer.Length);
1509+ m_fileData.SetLength(count * m_recordBuffer.Length);
15051510 }
15061511 }
15071512

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t