Skip site navigation (1) Skip section navigation (2)

Re: libpqxx testers needed!

From: "Llew Sion Goodstadt" <leo(dot)goodstadt(at)human-anatomy(dot)oxford(dot)ac(dot)uk>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpqxx testers needed!
Date: 2002-12-03 18:25:57
Message-ID: 00f901c29af9$6c3f30d0$1c1d01a3@FGU028 (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
One thing I am curious about is why strings are passed by value instead
of by constant reference.
Even granted that many standard library vendors *in the past* used
COW reference counting implementations of std::string to minimize the
cost of copying, this surely is still an unwarranted additional cost.

E.g. libpqxx-1.2.2\src\connection.cxx:427

Instead of:
void pqxx::Connection::BeginCopyRead(string Table)

Should be:
void pqxx::Connection::BeginCopyRead(const string& Table)
  Result R( Exec(("COPY " + Table + " TO STDOUT").c_str()) );

Of course if you are going to change the string anyway inside the body
of the function, pass by const
reference is misleading for both the compiler and the user, so pass
by value would be justified. E.g. if the above example had been 
something like

void pqxx::Connection::BeginCopyRead(string Table)
  Table = "COPY " + Table + " TO STDOUT";
  Result R( Exec(Table.c_str()) );

I have found few of these cases in libpqxx.

Leo Goodstadt
MRC Functional Genetics Unit

In response to


pgsql-interfaces by date

Next:From: Jeroen T. VermeulenDate: 2002-12-03 20:27:36
Subject: Re: libpqxx testers needed!
Previous:From: Llew Sion GoodstadtDate: 2002-12-03 17:08:20
Subject: Re: libpqxx testers needed!

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group