在Rebol中计算线路的最快/最有效的方法是什么?

rgc*_*ris 9 string performance newline rebol

给定一个字符串string,在其中计算行的最快/最有效的方法是什么?将接受任何风格的Rebol的最佳答案.我一直在假设parse [some [thru]]组合是遍历字符串的最快方式,但后来我不确定,因此转向SO:

count-lines: func [string [string!] /local count][
    parse/all string [
        (count: 1) some [thru newline (count: count + 1)]
    ]
    count
]
Run Code Online (Sandbox Code Playgroud)

要么:

count-lines: func [string [string!] /local count][
    count: 0
    until [
        count: count + 1
        not string: find/tail string newline
    ]
    count
]
Run Code Online (Sandbox Code Playgroud)

柜台怎么样?重复效率如何?

count-lines: func [string [string!]][
    repeat count length? string [
        unless string: find/tail string newline [
            break/return count
        ]
    ]
]
Run Code Online (Sandbox Code Playgroud)

更新:行计数采用文本编辑器原则:

空TextMate文档

空文档的行数仍为1.所以:

>> count-lines ""
== 1
>> count-lines "^/"
== 2
Run Code Online (Sandbox Code Playgroud)

Max*_*axV 2

这对我来说是最好的:

temp: read/lines %mytext.txt
length? temp
Run Code Online (Sandbox Code Playgroud)