1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| DeleteFile(GetTemporaryDirectory()+ "filetest.txt")
If CreateFile(0, GetTemporaryDirectory()+ "filetest.txt")
For Inc = 0 To 40000
;WriteString(0, LSet("", Random(255), "a")+Chr(10)) ; Linux
;WriteString(0, LSet("", Random(255), "b")+Chr(13)) ; MacOS
WriteString(0, LSet("", Random(255), "c")+Chr(13)+Chr(10)) ; Windows
Next
CloseFile(0)
EndIf
ProcedureDLL.s PeekLine(*BufMem = 0, BufLen = 0)
Protected *ptrChar.Character, *ptrStr.Character, *ptrEof
Protected lLength.l
Protected cChar.c, cCharBis.c
Static MemOffset, MemLen, *MemBuf
Static bSystem.b
If *BufMem And BufLen
*MemBuf = *BufMem
MemLen = BufLen
MemOffset = 0
EndIf
If *MemBuf And MemLen
*ptrChar = *MemBuf + MemOffset
*ptrEof = *MemBuf + MemLen
*ptrStr = *ptrChar
If MemOffset < MemLen
While *ptrChar< *ptrEof
cChar = *ptrChar\c
*ptrChar = *ptrChar + SizeOf(Character)
If cChar = 13
Break
EndIf
If cChar = 10
Break
EndIf
lLength + 1
Wend
If *ptrChar < *ptrEof
cCharBis = *ptrChar\c
If cCharBis + cChar = 23
*ptrChar = *ptrChar + SizeOf(Character)
EndIf
EndIf
MemOffset = *ptrChar - *MemBuf
ProcedureReturn PeekS(*ptrStr, lLength)
Else
ProcedureReturn Chr(1)
EndIf
Else
ProcedureReturn Chr(1)
EndIf
EndProcedure
lNbLines = 0
TimeStart.l = ElapsedMilliseconds()
Global Stream.l = ReadFile(#PB_Any, GetTemporaryDirectory()+ "filetest.txt")
If Stream
MemBufferLen = Lof(Stream)
If MemBufferLen
*MemBuffer = AllocateMemory(MemBufferLen)
If *MemBuffer
If ReadData(Stream, *MemBuffer, MemBufferLen) = MemBufferLen
CloseFile(Stream)
Line.s = PeekLine(*MemBuffer, MemBufferLen)
Repeat
lNbLines + 1
; Debug Line
Line = PeekLine()
Until Line = Chr(1)
FreeMemory(*MemBuffer)
EndIf
EndIf
EndIf
EndIf
TimeEnd.l = ElapsedMilliseconds()
Debug TimeStart
Debug TimeEnd
Debug "Time #1 > " + Str(TimeEnd - TimeStart)+"ms"
Debug lNbLines
lNbLines = 0
TimeStart.l = ElapsedMilliseconds()
Global Stream.l = ReadFile(#PB_Any, GetTemporaryDirectory()+ "filetest.txt")
If Stream
MemBufferLen = Lof(Stream)
If MemBufferLen
*MemBuffer = AllocateMemory(MemBufferLen)
If *MemBuffer
If ReadData(Stream, *MemBuffer, MemBufferLen) = MemBufferLen
FileContent.s = PeekS(*MemBuffer, MemBufferLen)
EndIf
CloseFile(Stream)
FreeMemory(*MemBuffer)
EndIf
EndIf
For Inc = 0 To CountString(FileContent, Chr(13)) - 1
Line = StringField(FileContent, Inc +1, Chr(13))
Line = RemoveString(Line, Chr(13))
Line = RemoveString(Line, Chr(10))
lNbLines + 1
; Debug Line
Next
EndIf
TimeEnd.l = ElapsedMilliseconds()
Debug TimeStart
Debug TimeEnd
Debug "Time #2 > " + Str(TimeEnd - TimeStart)+"ms"
Debug lNbLines
|