Performance improvement in tac
This commit is contained in:
parent
3778f7aad6
commit
bed37dc237
1 changed files with 7 additions and 8 deletions
15
tac.nim
15
tac.nim
|
|
@ -9,18 +9,17 @@ proc catFile(file:string) =
|
|||
f = open(file, fmRead)
|
||||
reverseLines: seq[string]
|
||||
for line in lines(f):
|
||||
reverseLines = line & reverseLines
|
||||
for line in reverseLines:
|
||||
writeLine(stdout, line)
|
||||
reverseLines.add(line)
|
||||
for i in low(reverseLines)..high(reverseLines):
|
||||
writeLine(stdout, reverseLines[high(reverseLines) - i])
|
||||
|
||||
proc catStdin() =
|
||||
var
|
||||
line = ""
|
||||
reverseLines: seq[string]
|
||||
while stdin.readLine(line):
|
||||
reverseLines = line & reverseLines
|
||||
for line in reverseLines:
|
||||
writeLine(stdout, line)
|
||||
for line in lines(stdin):
|
||||
reverseLines.add(line)
|
||||
for i in low(reverseLines)..high(reverseLines):
|
||||
writeLine(stdout, reverseLines[high(reverseLines) - i])
|
||||
|
||||
proc main(files:seq[string]) =
|
||||
if files.len == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue