tokyo.cabinet.abstract: Optimization, deserialize objects directly from memory, without the intermediate bytes-array
parent
62e9ee0ed9
commit
dba87c8d70
|
@ -1,11 +1,20 @@
|
||||||
! Copyright (C) 2009 Bruno Deferrari
|
! Copyright (C) 2009 Bruno Deferrari
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types arrays assocs destructors kernel libc locals
|
USING: accessors alien.c-types arrays assocs destructors
|
||||||
|
io io.streams.memory kernel libc locals
|
||||||
sequences serialize tokyo.alien.tcadb tokyo.alien.tcutil vectors ;
|
sequences serialize tokyo.alien.tcadb tokyo.alien.tcutil vectors ;
|
||||||
IN: tokyo.cabinet.abstract
|
IN: tokyo.cabinet.abstract
|
||||||
|
|
||||||
TUPLE: tokyo-abstractdb handle disposed ;
|
TUPLE: tokyo-abstractdb handle disposed ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
: with-memory-reader ( memory quot -- )
|
||||||
|
[ <memory-stream> ] dip with-input-stream* ; inline
|
||||||
|
|
||||||
|
: memory>object ( memory -- object )
|
||||||
|
[ deserialize ] with-memory-reader ;
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
INSTANCE: tokyo-abstractdb assoc
|
INSTANCE: tokyo-abstractdb assoc
|
||||||
|
|
||||||
: <tokyo-abstractdb> ( name -- tokyo-abstractdb )
|
: <tokyo-abstractdb> ( name -- tokyo-abstractdb )
|
||||||
|
@ -21,7 +30,7 @@ M:: tokyo-abstractdb at* ( key db -- value/f ? )
|
||||||
kbytes length :> key-size
|
kbytes length :> key-size
|
||||||
handle kbytes key-size sizeout tcadbget :> output
|
handle kbytes key-size sizeout tcadbget :> output
|
||||||
output [
|
output [
|
||||||
[ sizeout *int memory>byte-array ] [ tcfree ] bi bytes>object t
|
[ memory>object ] [ tcfree ] bi t
|
||||||
] [ f f ] if* ;
|
] [ f f ] if* ;
|
||||||
|
|
||||||
M: tokyo-abstractdb assoc-size ( db -- size ) handle>> tcadbrnum ;
|
M: tokyo-abstractdb assoc-size ( db -- size ) handle>> tcadbrnum ;
|
||||||
|
@ -33,8 +42,8 @@ M:: tokyo-abstractdb >alist ( db -- alist )
|
||||||
db assoc-size <vector> :> keys
|
db assoc-size <vector> :> keys
|
||||||
handle tcadbiterinit drop
|
handle tcadbiterinit drop
|
||||||
[ handle size-out tcadbiternext dup ] [
|
[ handle size-out tcadbiternext dup ] [
|
||||||
[ size-out *int memory>byte-array ] [ tcfree ] bi
|
[ memory>object ] [ tcfree ] bi
|
||||||
bytes>object keys push
|
keys push
|
||||||
] while drop
|
] while drop
|
||||||
keys [ dup db at 2array ] { } map-as ;
|
keys [ dup db at 2array ] { } map-as ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue