AutoHotkey Community

It is currently May 27th, 2012, 12:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: February 15th, 2011, 11:43 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
A new function by rseding91 ReverseDirectionByNewline see
http://www.autohotkey.com/forum/viewtop ... 636#421636
Quote:
---------------------------
Benchmark Results 5 Runs with 10 Rounds
---------------------------

SetBatchLines, 20 / Critical, Off / Process Priority Normal
0.169696 sec (randallf's original function)
0.060313 sec (dR's reverse - I (loop w/ ternary))
0.355854 sec (dR's reverse - II (recursive sort callback))
0.056551 sec (dR's reverse - III (loop w/ substring))
0.112973 sec (jBalli's jReverse I)
0.002383 sec (ReverseDirectionByNewline by rseding91)
0.000789 sec (QPC Benchmark BuildIn)

SetBatchLines, -1 / Critical, Off / Process Priority Normal
0.000451 sec (randallf's original function)
0.000481 sec (dR's reverse - I (loop w/ ternary))
0.001583 sec (dR's reverse - II (recursive sort callback))
0.000479 sec (dR's reverse - III (loop w/ substring))
0.000777 sec (jBalli's jReverse I)
0.000015 sec (ReverseDirectionByNewline by rseding91)
0.000600 sec (QPC Benchmark BuildIn)

SetBatchLines, -1 / Critical, On / Process Priority Normal
0.000402 sec (randallf's original function)
0.000440 sec (dR's reverse - I (loop w/ ternary))
0.001491 sec (dR's reverse - II (recursive sort callback))
0.000448 sec (dR's reverse - III (loop w/ substring))
0.000664 sec (jBalli's jReverse I)
0.000012 sec (ReverseDirectionByNewline by rseding91)
0.000398 sec (QPC Benchmark BuildIn)

SetBatchLines, -1 / Critical, On / Process Priority Realtime
0.000563 sec (randallf's original function)
0.000567 sec (dR's reverse - I (loop w/ ternary))
0.001801 sec (dR's reverse - II (recursive sort callback))
0.000553 sec (dR's reverse - III (loop w/ substring))
0.000900 sec (jBalli's jReverse I)
0.000018 sec (ReverseDirectionByNewline by rseding91)
0.000529 sec (QPC Benchmark BuildIn)


test script (not sure if it is OK like this due to byref var usage of ReverseDirectionByNewline)

Code:
; QueryPerfomanceCounter - Benchmark Skript
; Version 1.0 (w) 2008 by DerRaphael / zLib License Style Release

DllCall("QueryPerformanceFrequency", "Int64*", BenchMark[F])
; BENCHMARK START
; Äußere Runden / Outer Rounds
@OR := 5
; Innere Läufe / Inner Runs
@IR := 10

; INIT VAR - use for simplicity this script as source
Gosub, GetVariable
Gosub, BuildRef

; Start Benchmark
Loop,4
{
   Setting := A_Index
   SetBatchLines, 20
   Critical, Off
   Process, Priority,, Normal
   if (A_Index = 1) {
      CurrentSettings := "SetBatchLines, 20 / Critical, Off / Process Priority Normal"
   } else if (A_Index = 2) {
      CurrentSettings := "SetBatchLines, -1 / Critical, Off / Process Priority Normal"
      SetBatchLines, -1
      Critical, Off
      Process, Priority,, Normal
   } else if (A_Index = 3) {
      CurrentSettings := "SetBatchLines, -1 / Critical, On / Process Priority Normal"
      SetBatchLines, -1
      Critical, On
      Process, Priority,, Normal
   } else if (A_Index = 4) {
      CurrentSettings := "SetBatchLines, -1 / Critical, On / Process Priority Realtime"
      SetBatchLines, -1
      Critical, On
      Process, Priority,, R
   }
   OfficialResult .= "`n" CurrentSettings "`n"
   
   Loop, % @OR
   {
      A_Run := A_Index
      Loop, % @IR
      {
         ; Zähler der auszuführenden Tests / Count of Tests to accomplish
         A_Test := 0
         
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "randallf's original function"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := ReverseLines(var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "dR's reverse - I (loop w/ ternary)"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := reverse(var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "dR's reverse - II (recursive sort callback)"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := reverse2(var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "dR's reverse - III (loop w/ substring)"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := reverse3(var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "jBalli's jReverse I"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := jReverse(var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "ReverseDirectionByNewline by rseding91"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
         ReverseDirectionByNewline(byref var)
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
         ; SOBM***********************************************************************************
         A_Test+=1
         
         if !StrLen(Desc[%A_Test%])
            Desc[%A_Test%] := "QPC Benchmark BuildIn"
           
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[SC]) ; StartCounter
         
         ; Hier komme hinein, was getestet wird / Insert what needs to be tested
       res := QPC_BenchmarkInternal( Var )
         ; Hier ist zuende, was getestet wurde / End of whatever has been tested
         
         DllCall("QueryPerformanceCounter", "Int64 *", BenchMark[EC]) ; EndCounter
         
         Result[%A_Test%][%A_Run%][%A_Index%] := (BenchMark[EC] - BenchMark[SC]) / BenchMark[F]
     
       if ( res != ref )
         MsgBox FAIL@%A_Test%
         ; ***********************************************************************************EOBM
      }
      ; Zeiten mitteln / Average Timings
      Loop, % A_Test
      {
         A_Test := A_Index
         Result[%A_Test%][%A_Run%] := 0
         Loop, % @IR
            Result[%A_Test%][%A_Run%] += Result[%A_Test%][%A_Run%][%A_Index%]
         Result[%A_Test%][%A_Run%] /= @IR
      }
   }
   ; BENCHMARK END
   ; Resultate ermitteln / Calculate Results
   Loop, % A_Test
   {
      A_Test := A_Index
      Result[%A_Test%] := 0
      Loop, % A_Run
         Result[%A_Test%] += Result[%A_Test%][%A_Index%]
      Result[%A_Test%] /= @OR
      OfficialResult .= Result[%A_Test%] " sec`t(" Desc[%A_Test%] ")`n"
   }
}
SetBatchLines, 20
Critical, Off
Process, Priority,, Normal

MsgBox,64,Benchmark Results %@OR% Runs with %@IR% Rounds, %OfficialResult%
ExitApp

ReverseDirectionByNewline(byref var,Delimiter="`n",Omit="")
{
   Local FastRtlMoveMemory, Offset, T1, T2, T3
MsgBox
   If (StrLen(Delimiter) > 1 or StrLen(Omit) > 1)
      Return -1
   FastRtlMoveMemory := DllCall("GetProcAddress", A_IsUnicode ? Ptr : uint, DllCall("GetModuleHandle", "str", "kernel32.dll"), A_IsUnicode ? AStr : str, "RtlMoveMemory")
   Offset := StrLen(var), T1 := &var
   If (A_IsUnicode){
      Offset *= 2
      Loop, Parse, var,%Delimiter%,%Omit%
         T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2)*2, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   } Else {
      Loop, Parse, var,%Delimiter%,%Omit%
         T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2), Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   }
}

; TEST FUNCTIONS
; Randallf's Original Function
ReverseLines(InputVar) ;reverses lines in a variable read from a file that was delimited by `n
{
   StringSplit, a, InputVar, `n
   While a0
   {
      If Reversed
      {
         Reversed := Reversed . "`n" . a%a0%
      }
      Else
      {
         Reversed := a%a0%
      }
     
      a0--
   }
   Return Reversed
}

; dR I
reverse(var) {
   Loop,Parse,var,`n
      n := a_loopfield ( strlen( n ) ? "`n" : "" ) n
   return n
}
; dR II
reverse2( a,b = "",c = "init" ) { ; adapted from sort help's last sample
   if ( c != "init" )
      return c
   else
      sort,a,% "F " A_ThisFunc
   return a
}
; dR III
reverse3(var) {
   Loop,Parse,var,`n
      n := a_loopfield "`n" n
   return SubStr( n,1,-1 )
}
; jBally I
jReverse(p_Data)
    {
    l_AutoTrim:=A_AutoTrim
    AutoTrim off
    VarSetCapacity(Reversed,StrLen(p_Data))
    loop parse,p_Data,`n,`r
        if StrLen(Reversed)=0
            Reversed:=A_LoopField
         else
            Reversed=%A_LoopField%`n%Reversed%
    AutoTrim %l_AutoTrim%
    return Reversed
   }
; buildIn
QPC_BenchmarkInternal( Var )
{
   sort, var, F SortDummyCallBack
   return var
}

GetVariable:
var =
(Ltrim Join`n
   Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
   sed diam nonumy eirmod tempor invidunt ut labore et dolore
   magna aliquyam erat, sed diam voluptua. At vero eos et
   accusam et justo duo dolores et ea rebum. Stet clita kasd
   gubergren, no sea takimata sanctus est Lorem ipsum dolor
   sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing
   elitr,  sed diam nonumy eirmod tempor invidunt ut labore et
   dolore magna aliquyam erat, sed diam voluptua. At vero eos
   et accusam et justo duo dolores et ea rebum. Stet clita
   kasd gubergren, no sea takimata sanctus est Lorem ipsum
   dolor sit amet. Lorem ipsum dolor sit amet, consetetur
   sadipscing elitr,  sed diam nonumy eirmod tempor invidunt
   ut labore et dolore magna aliquyam erat, sed diam voluptua.
   At vero eos et accusam et justo duo dolores et ea rebum.
   Stet clita kasd gubergren, no sea takimata sanctus est
   Lorem ipsum dolor sit amet.
   Duis autem vel eum iriure dolor in hendrerit in vulputate
   velit esse molestie consequat, vel illum dolore eu feugiat
   nulla facilisis at vero eros et accumsan et iusto odio
   dignissim qui blandit praesent luptatum zzril delenit augue
   duis dolore te feugait nulla facilisi. Lorem ipsum dolor
   sit amet, consectetuer adipiscing elit, sed diam nonummy
   nibh euismod tincidunt ut laoreet dolore magna aliquam erat
   volutpat.
   Ut wisi enim ad minim veniam, quis nostrud exerci tation
   ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo
   consequat. Duis autem vel eum iriure dolor in hendrerit in
   vulputate velit esse molestie consequat, vel illum dolore
   eu feugiat nulla facilisis at vero eros et accumsan et iusto
   odio dignissim qui blandit praesent luptatum zzril delenit
   augue duis dolore te feugait nulla facilisi.
   Nam liber tempor cum soluta nobis eleifend option congue
   nihil imperdiet doming id quod mazim placerat facer possim
   assum. Lorem ipsum dolor sit amet, consectetuer adipiscing
   elit, sed diam nonummy nibh euismod tincidunt ut laoreet
   dolore magna aliquam erat volutpat. Ut wisi enim ad minim
   veniam, quis nostrud exerci tation ullamcorper suscipit
   lobortis nisl ut aliquip ex ea commodo consequat.
   Duis autem vel eum iriure dolor in hendrerit in vulputate
   velit esse molestie consequat, vel illum dolore eu feugiat
   nulla facilisis.
   At vero eos et accusam et justo duo dolores et ea rebum.
   Stet clita kasd gubergren, no sea takimata sanctus est
   Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
   consetetur sadipscing elitr,  sed diam nonumy eirmod tempor
   invidunt ut labore et dolore magna aliquyam erat, sed diam
   voluptua. At vero eos et accusam et justo duo dolores et ea
   rebum. Stet clita kasd gubergren, no sea takimata sanctus
   est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
   consetetur sadipscing elitr,  At accusam aliquyam diam diam
   dolore dolores duo eirmod eos erat, et nonumy sed tempor et
   et invidunt justo labore Stet clita ea et gubergren, kasd
   magna no rebum. sanctus sea sed takimata ut vero voluptua.
   est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
   consetetur sadipscing elitr,  sed diam nonumy eirmod tempor
   invidunt ut labore et dolore magna aliquyam erat.
   Consetetur sadipscing elitr,  sed diam nonumy eirmod tempor
   invidunt ut labore et dolore magna aliquyam erat, sed diam
   voluptua. At vero eos et accusam et justo duo dolores et ea
   rebum. Stet clita kasd gubergren, no sea takimata sanctus est
   Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
   consetetur sadipscing elitr,  sed diam nonumy eirmod tempor
   invidunt ut labore et dolore magna aliquyam erat, sed diam
   voluptua. At vero eos et accusam et justo duo dolores et ea
   rebum. Stet clita kasd gubergren, no sea takimata sanctus est
   Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
   consetetur sadipscing elitr,  sed diam nonumy eirmod tempor
   invidunt ut labore et dolore magna aliquyam erat, sed diam
   voluptua. At vero eos et accusam et justo duo dolores et ea
   rebum. Stet clita kasd gubergren, no sea takimata sanctus
   est Lorem ipsum dolor sit amet.
)
Return

BuildRef:
   Ref := var
   Sort,Ref,F SortDummyCallBack
Return

SortDummyCallBack(a,b,c)
{
   return c
}
[/quote]

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2011, 5:50 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
i don't think >>QueryPerformanceCounter<< is prefered above A_TickCount.

also why is this done?
Code:
; dR I
reverse(var) {
   Loop,Parse,var,`n
      n := a_loopfield ( strlen( n ) ? "`n" : "" ) n
   return n
}
Why not using this?
Code:
; dR I
reverse(var) {
   Loop,Parse,var,`n
      n .= n ? "`n" A_LoopField : A_LoopField
   return n
}
No extra function call (strlen( n ) )

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2011, 7:06 pm 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Hugov: change "ReverseDirectionByNewline(byref var)" to "ReverseDirectionByNewline(var,"`n")"

Emmanuel d: the way you have it it is simply reassembling the variable in the same order it started as. You would need to do it like this:

Code:
; dR I
reverse(var) {
   Loop,Parse,var,`n
      n .= n ? "`n" A_LoopField n : A_LoopField n
   return n
}


Although, it's still going to take ages to reverse a large variable. You would be beter off using my function that Hugov posted as it can handle huge (60 MB 1 million line) variables in under 10 seconds even on netbooks.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2011, 7:38 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
hahahaha you are wright :D
i should have tested it first 8)
you also forgot to replace the dot for : and "`n" needs to be between A_LoopField and n
ques you also didnt test :P
like
Code:
; dR I
reverse(var) {
   Loop,Parse,var,`n
      n := n ? A_LoopField  "`n" n : A_LoopField ; adding in front of the var
   return n
}


Quote:
You would be beter off using my function that Hugov posted as it can handle huge (60 MB 1 million line) variables in under 10 seconds even on netbooks.
i like that. i must test it

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2011, 5:35 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
rseding91 wrote:
Hugov: change "ReverseDirectionByNewline(byref var)" to "ReverseDirectionByNewline(var,"`n")"
Try it, it doesn't work (not that it matters much I guess. (for some reason the test script reports fail@6 which is your function in the test script.)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2011, 8:32 pm 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Revised function: Added checks for dealing with different types of splits.

Code:
ReverseDirectionByNewline(byref var,Delimiter="`n",Omit="")
{
   Local Offset, T1, T2, T3, T4
   Static FastRtlMoveMemory
   If (StrLen(Delimiter) > 1 or StrLen(Omit) > 1)
      Return -1
   If !FastRTLMoveMemory
      FastRtlMoveMemory := DllCall("GetProcAddress", A_IsUnicode ? Ptr : uint, DllCall("GetModuleHandle", "str", "kernel32.dll"), A_IsUnicode ? AStr : str, "RtlMoveMemory")
   Offset := StrLen(var), T1 := &var
   If Omit
      T4 := SubStr(Var,-1), T4 := T4 = Delimiter Omit ? 1 : 0
   Else
      T4 := SubStr(Var,0), T4 := T4 = Delimiter ? 1 : 0
   If (A_IsUnicode){
      Offset *= 2
      If (T4){
         Loop, Parse, var,%Delimiter%,%Omit%
            T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2)*2, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
      } Else {
         Loop, Parse, var,%Delimiter%,%Omit%
            T2 := A_Index = 1 ? A_LoopField : A_LoopField Delimiter Omit, T3 := StrLen(T2)*2, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
      }
   } Else {
      If (T4){
         Loop, Parse, var,%Delimiter%,%Omit%
            T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2), Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
      } Else {
         Loop, Parse, var,%Delimiter%,%Omit%
            T2 := A_Index = 1 ? A_LoopField : A_LoopField Delimiter Omit, T3 := StrLen(T2), Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
      }
   }
}

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2011, 5:08 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
i made it a litle shorter:
Code:
ReverseDirectionByNewline(byref var,Delimiter="`n",Omit="") {
   Local Offset, T1, T2, T3, T4
   Static FastRtlMoveMemory
   If (StrLen(Delimiter) > 1 or StrLen(Omit) > 1)
      Return -1
   If !FastRTLMoveMemory
      FastRtlMoveMemory := DllCall("GetProcAddress", A_IsUnicode ? Ptr : uint, DllCall("GetModuleHandle", "str", "kernel32.dll"), A_IsUnicode ? AStr : str, "RtlMoveMemory")
   Offset := StrLen(var), T1 := &var
   Omit ? (T4 := SubStr(Var,-1), T4 := T4 = Delimiter Omit ? 1 : 0) : (T4 := SubStr(Var,0), T4 := T4 = Delimiter ? 1 : 0)
   A_IsUnicode ? Offset *= mp := 2 : mp := 1
   If (T4)
      Loop, Parse, var,%Delimiter%,%Omit%
         T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2)*mp, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   Else Loop, Parse, var,%Delimiter%,%Omit%
      T2 := A_Index = 1 ? A_LoopField : A_LoopField Delimiter Omit, T3 := StrLen(T2)*mp, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   }
hope it doesn't slow it down

i also think we can remove
Quote:
Local Offset, T1, T2, T3, T4
than variables will be local by default

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2011, 5:24 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
i am using this now:
Code:
ReverseDirectionByNewline(byref var,Delimiter="`n",Omit="") {
   Static FastRtlMoveMemory
   If (StrLen(Delimiter) > 1 or StrLen(Omit) > 1)
      Return -1
   If !FastRTLMoveMemory
      FastRtlMoveMemory := DllCall("GetProcAddress", A_IsUnicode ? Ptr : uint, DllCall("GetModuleHandle", "str", "kernel32.dll"), A_IsUnicode ? AStr : str, "RtlMoveMemory")
   Offset := StrLen(var), T1 := &var
   Omit ? (T4 := SubStr(Var,-1), T4 := T4 = Delimiter Omit ? 1 : 0) : (T4 := SubStr(Var,0), T4 := T4 = Delimiter ? 1 : 0)
   A_IsUnicode ? Offset *= mp := 2 : mp := 1
   IfNotEqual,T4,%False%,Loop,Parse,var,%Delimiter%,%Omit%
      T2 := A_LoopField Delimiter Omit, T3 := StrLen(T2)*mp, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   Else Loop,Parse,var,%Delimiter%,%Omit%
      T2 := A_Index = 1 ? A_LoopField : A_LoopField Delimiter Omit, T3 := StrLen(T2)*mp, Offset -= T3, DllCall(FastRtlMoveMemory,"UInt",T1 + Offset,"UInt",&T2,"UInt",T3)
   }

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Bon, maul.esel and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group