Mercurial > repos > rhope
changeset 104:2d2da148d844
Performance improvement for string comparisons
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 25 Aug 2010 03:19:57 +0000 |
parents | 7428aa5d6ade |
children | 439db471f595 a7add4db4a25 |
files | runtime/array.c runtime/array.h string.rhope |
diffstat | 3 files changed, 69 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/array.c Wed Aug 11 03:13:28 2010 -0400 +++ b/runtime/array.c Wed Aug 25 03:19:57 2010 +0000 @@ -170,4 +170,8 @@ release_ref((object *)bp); } +int32_t _internal_memcmp_offset(void * left, int32_t loff, void * right, int32_t roff, int32_t len) +{ + return memcmp(((char *)left)+loff, ((char *)right)+roff, len); +}
--- a/runtime/array.h Wed Aug 11 03:13:28 2010 -0400 +++ b/runtime/array.h Wed Aug 25 03:19:57 2010 +0000 @@ -13,6 +13,7 @@ object *_internal_array_allocboxedcopy(object * osource, int32_t size); object * _internal_array_allocnaked(int32_t size , object * type); object * _internal_array_allocnakedcopy(object * osource, int32_t size); +int32_t _internal_memcmp_offset(void * left, int32_t loff, void * right, int32_t roff, int32_t len); void internalarrayboxedcopy(object * obj); void internalarraynakedcopy(object * obj); void internalarrayboxedcleanup(object * obj);
--- a/string.rhope Wed Aug 11 03:13:28 2010 -0400 +++ b/string.rhope Wed Aug 25 03:19:57 2010 +0000 @@ -460,17 +460,7 @@ { [left]Byte[index] { - rbyte <- [right]Byte[index] {} - { - Print[["Could not fetch byte from right string at offset:"]Append[String[index]]] - { Print[["Right string has type ID: "]Append[ String[ID[Blueprint Of[right]]] ]] - { Print[[right]Byte Length] - { Print[[right]Length] - { Print[["Left string has type ID: "]Append[ String[ID[Blueprint Of[left]]] ]] - { Print[[left]Byte Length] - { Print[[left]Length] }}}}}} - out <- No - } + rbyte <- [right]Byte[index] ,out <- If[[~]=[rbyte]] { out <- _=String[left,right,[index]+[1]] @@ -488,9 +478,50 @@ } } +Foreign C:libc +{ + memcmp[a(Array,Raw Pointer),b(Array,Raw Pointer),len(Int64,Naked):out(Int32,Naked)] +} + +Foreign C:runtime +{ + _internal_memcmp_offset[left(Array,Raw Pointer),loffset(Int32,Naked),right(Array,Raw Pointer),roffset(Int32,Naked),len(Int32,Naked):out(Int32,Naked)] +} + +_Flat=@String[left,right:out] +{ + ,out <- If[[[left]Byte Length] = [[right]Byte Length]] + { + If[memcmp[[left]Buffer >>, [right]Buffer >>, Int64[[left]Byte Length]]] + { + out <- No + }{ + out <- Yes + } + } +} + +_Flat=@String Slice[left,right:out] +{ + ,out <- If[[[left]Byte Length] = [[right]Byte Length]] + { + If[_internal_memcmp_offset[[[left]Source >>]Buffer >>, [left]Offset >>, [right]Buffer >>, 0i32, [left]Byte Length]] + { + out <- No + }{ + out <- Yes + } + } +} + +_Flat=@String Cat[left,right:out] +{ + out <- Eq String[left,right] +} + =@String[left,right:out] { - out <- Eq String[left,right] + out <- [right]_Flat=[left] } Byte Length@String[string:out] @@ -534,9 +565,29 @@ out <- [string]Length >> } +_Slice=@String Slice[left,right:out] +{ + ,out <- If[[[left]Byte Length]=[[right]Byte Length]] + { + If[_internal_memcmp_offset[[[left]Source >>]Buffer >>, [left]Offset >>, [[right]Source >>]Buffer >>, [right]Offset >>, [left]Byte Length]] + { out <- No } + { out <- Yes } + } +} + +_Slice=@String[left,right:out] +{ + out <- [right]_Flat=[left] +} + +_Slice=@String Cat[left,right:out] +{ + out <- Eq String[left,right] +} + =@String Slice[left,right:out] { - out <- Eq String[left,right] + out <- [right]_Slice=[left] } _Flatten@String[string,dest,offset,count:out]