Faster conversion of sbufs, vectors and byte-vectors to their corresponding fixed-size type respectively; we call the resize-T primitive on the underlying sequence instead of >T
parent
fa146b248a
commit
252b1eb513
|
@ -16,8 +16,6 @@ M: object new-sequence drop f <array> ;
|
|||
|
||||
M: f new-sequence drop dup zero? [ drop f ] [ f <array> ] if ;
|
||||
|
||||
M: array like drop dup array? [ >array ] unless ;
|
||||
|
||||
M: array equal?
|
||||
over array? [ sequence= ] [ 2drop f ] if ;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ M: byte-array length length>> ;
|
|||
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
|
||||
M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
|
||||
: >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
|
||||
M: byte-array like drop dup byte-array? [ >byte-array ] unless ;
|
||||
M: byte-array new-sequence drop <byte-array> ;
|
||||
|
||||
M: byte-array equal?
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel kernel.private math sequences
|
||||
sequences.private growable byte-arrays ;
|
||||
sequences.private growable byte-arrays accessors ;
|
||||
IN: byte-vectors
|
||||
|
||||
TUPLE: byte-vector
|
||||
|
@ -26,6 +26,19 @@ M: byte-vector new-sequence
|
|||
M: byte-vector equal?
|
||||
over byte-vector? [ sequence= ] [ 2drop f ] if ;
|
||||
|
||||
M: byte-array like
|
||||
#! If we have an byte-array, we're done.
|
||||
#! If we have a byte-vector, and it's at full capacity,
|
||||
#! we're done. Otherwise, call resize-byte-array, which is a
|
||||
#! relatively fast primitive.
|
||||
drop dup byte-array? [
|
||||
dup byte-vector? [
|
||||
[ length ] [ underlying>> ] bi
|
||||
2dup length eq?
|
||||
[ nip ] [ resize-byte-array ] if
|
||||
] [ >byte-array ] if
|
||||
] unless ;
|
||||
|
||||
M: byte-array new-resizable drop <byte-vector> ;
|
||||
|
||||
INSTANCE: byte-vector growable
|
||||
|
|
|
@ -31,16 +31,16 @@ M: sbuf equal?
|
|||
M: string new-resizable drop <sbuf> ;
|
||||
|
||||
M: string like
|
||||
#! If we have a string, we're done.
|
||||
#! If we have an sbuf, and it's at full capacity, we're done.
|
||||
#! Otherwise, call resize-string, which is a relatively
|
||||
#! fast primitive.
|
||||
drop dup string? [
|
||||
dup sbuf? [
|
||||
dup length over underlying>> length eq? [
|
||||
underlying>> dup reset-string-hashcode
|
||||
] [
|
||||
>string
|
||||
] if
|
||||
] [
|
||||
>string
|
||||
] if
|
||||
[ length ] [ underlying>> ] bi
|
||||
2dup length eq?
|
||||
[ nip dup reset-string-hashcode ] [ resize-string ] if
|
||||
] [ >string ] if
|
||||
] unless ;
|
||||
|
||||
INSTANCE: sbuf growable
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel math sequences sequences.private growable ;
|
||||
USING: arrays kernel math sequences sequences.private growable
|
||||
accessors ;
|
||||
IN: vectors
|
||||
|
||||
TUPLE: vector
|
||||
|
@ -22,6 +23,19 @@ M: vector new-sequence
|
|||
M: vector equal?
|
||||
over vector? [ sequence= ] [ 2drop f ] if ;
|
||||
|
||||
M: array like
|
||||
#! If we have an array, we're done.
|
||||
#! If we have a vector, and it's at full capacity, we're done.
|
||||
#! Otherwise, call resize-array, which is a relatively
|
||||
#! fast primitive.
|
||||
drop dup array? [
|
||||
dup vector? [
|
||||
[ length ] [ underlying>> ] bi
|
||||
2dup length eq?
|
||||
[ nip ] [ resize-array ] if
|
||||
] [ >array ] if
|
||||
] unless ;
|
||||
|
||||
M: sequence new-resizable drop <vector> ;
|
||||
|
||||
INSTANCE: vector growable
|
||||
|
|
Loading…
Reference in New Issue