@@ -96,9 +96,11 @@ impl StatementPoolingManager {
9696
9797impl r2d2:: PoolManager < Connection , Error > for StatementPoolingManager {
9898 fn connect ( & self ) -> Result < Connection , Error > {
99+ let cache = box RefCell :: new ( LruCache :: < String , PostgresStatement < ' static > > :: new (
100+ self . config . statement_pool_size ) ) ;
99101 Ok ( Connection {
100102 conn : box try!( self . manager . connect ( ) ) ,
101- stmts : RefCell :: new ( LruCache :: new ( self . config . statement_pool_size ) )
103+ stmts : unsafe { mem :: transmute ( cache ) } ,
102104 } )
103105 }
104106
@@ -133,21 +135,26 @@ pub trait GenericConnection {
133135
134136pub struct Connection {
135137 conn : Box < PostgresConnection > ,
136- stmts : RefCell < LruCache < String , Rc < PostgresStatement < ' static > > > > ,
138+ stmts : * mut ( ) ,
137139}
138140
139- #[ unsafe_destructor]
140141impl Drop for Connection {
141- // Just make sure that all the statements drop before the connection
142142 fn drop ( & mut self ) {
143- self . stmts . borrow_mut ( ) . change_capacity ( 0 ) ;
143+ let _: Box < RefCell < LruCache < String , Rc < PostgresStatement < ' static > > > > > =
144+ unsafe { mem:: transmute ( self . stmts ) } ;
145+ }
146+ }
147+
148+ impl Connection {
149+ fn get_cache ( & self ) -> & RefCell < LruCache < String , Rc < PostgresStatement < ' static > > > > {
150+ unsafe { mem:: transmute ( self . stmts ) }
144151 }
145152}
146153
147154impl GenericConnection for Connection {
148155 fn prepare < ' a > ( & ' a self , query : & str ) -> PostgresResult < Rc < PostgresStatement < ' a > > > {
149156 let query = query. into_string ( ) ;
150- let mut stmts = self . stmts . borrow_mut ( ) ;
157+ let mut stmts = self . get_cache ( ) . borrow_mut ( ) ;
151158
152159 if let Some ( stmt) = stmts. get ( & query) {
153160 return Ok ( unsafe { mem:: transmute ( stmt. clone ( ) ) } ) ;
@@ -183,7 +190,7 @@ pub struct Transaction<'a> {
183190impl < ' a > GenericConnection for Transaction < ' a > {
184191 fn prepare < ' a > ( & ' a self , query : & str ) -> PostgresResult < Rc < PostgresStatement < ' a > > > {
185192 let query = query. into_string ( ) ;
186- let mut stmts = self . conn . stmts . borrow_mut ( ) ;
193+ let mut stmts = self . conn . get_cache ( ) . borrow_mut ( ) ;
187194
188195 if let Some ( stmt) = stmts. get ( & query) {
189196 return Ok ( unsafe { mem:: transmute ( stmt. clone ( ) ) } ) ;
0 commit comments