Skip to content

Commit

Permalink
Remove allocation, avoid double container search
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 22, 2024
1 parent 3ecd554 commit 08746bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/tao/pq/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace tao::pq
[[nodiscard]] auto transaction( const isolation_level il, const access_mode am = access_mode::default_access_mode ) -> std::shared_ptr< pq::transaction >;

void prepare( const std::string& name, const std::string& statement );
void deallocate( const std::string& name );
void deallocate( const std::string_view name );

template< typename... As >
auto execute( const internal::zsv statement, As&&... as )
Expand Down
9 changes: 5 additions & 4 deletions src/lib/pq/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,15 @@ namespace tao::pq
m_prepared_statements.insert( name );
}

void connection::deallocate( const std::string& name )
void connection::deallocate( const std::string_view name )
{
connection::check_prepared_name( name );
if( !connection::is_prepared( name ) ) {
throw std::runtime_error( "prepared statement not found: " + name );
const auto it = m_prepared_statements.find( name );
if( it == m_prepared_statements.end() ) {
throw std::runtime_error( std::format( "prepared statement not found: {}", name ) );
}
connection::execute( "DEALLOCATE " + connection::escape_identifier( name ) );
m_prepared_statements.erase( name );
m_prepared_statements.erase( it );
}

void connection::listen( const std::string_view channel )
Expand Down

0 comments on commit 08746bd

Please sign in to comment.