Use const char* instead of static const std::string

pull/28/head
Tatsuhiro Tsujikawa 2012-09-24 23:20:43 +09:00
parent 0144397e4b
commit d8c44fe9e8
10 changed files with 30 additions and 52 deletions

View File

@ -187,9 +187,8 @@ void DefaultBtInteractive::addPortMessageToQueue()
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
{
static const std::string CLIENT_ARIA2("aria2/"PACKAGE_VERSION);
HandshakeExtensionMessageHandle m(new HandshakeExtensionMessage());
m->setClientVersion(CLIENT_ARIA2);
m->setClientVersion("aria2/" PACKAGE_VERSION);
m->setTCPPort(tcpPort_);
m->setExtensions(extensionMessageRegistry_->getExtensions());
SharedHandle<TorrentAttribute> attrs =

View File

@ -48,18 +48,6 @@
namespace aria2 {
namespace {
static const std::string DEBUG_LABEL("DEBUG");
static const std::string INFO_LABEL("INFO");
static const std::string NOTICE_LABEL("NOTICE");
static const std::string WARN_LABEL("WARN");
static const std::string ERROR_LABEL("ERROR");
} // namespace
Logger::Logger()
: logLevel_(Logger::A2_DEBUG),
stdoutField_(0)
@ -104,21 +92,21 @@ bool Logger::levelEnabled(LEVEL level)
}
namespace {
const std::string& levelToString(Logger::LEVEL level)
const char* levelToString(Logger::LEVEL level)
{
switch(level) {
case Logger::A2_DEBUG:
return DEBUG_LABEL;
return "DEBUG";
case Logger::A2_INFO:
return INFO_LABEL;
return "INFO";
case Logger::A2_NOTICE:
return NOTICE_LABEL;
return "NOTICE";
case Logger::A2_WARN:
return WARN_LABEL;
return "WARN";
case Logger::A2_ERROR:
return ERROR_LABEL;
return "ERROR";
default:
return A2STR::NIL;
return "";
}
}
} // namespace
@ -138,8 +126,7 @@ void writeHeader
size_t dateLength =
strftime(datestr, sizeof(datestr), "%Y-%m-%d %H:%M:%S", &tm);
assert(dateLength <= (size_t)20);
fp.printf("%s.%06ld %s - ", datestr, tv.tv_usec,
levelToString(level).c_str());
fp.printf("%s.%06ld %s - ", datestr, tv.tv_usec, levelToString(level));
if(sourceFile) {
fp.printf("[%s:%d]", sourceFile, lineNum);
}

View File

@ -846,8 +846,8 @@ std::string RequestGroup::getFirstFilePath() const
{
assert(downloadContext_);
if(inMemoryDownload()) {
static const std::string DIR_MEMORY("[MEMORY]");
return DIR_MEMORY+File(downloadContext_->getFirstFileEntry()->getPath()).getBasename();
return "[MEMORY]"+
File(downloadContext_->getFirstFileEntry()->getPath()).getBasename();
} else {
return downloadContext_->getFirstFileEntry()->getPath();
}

View File

@ -713,11 +713,6 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
void RequestGroupMan::showDownloadResults(OutputFile& o, bool full) const
{
static const std::string MARK_OK("OK");
static const std::string MARK_ERR("ERR");
static const std::string MARK_INPR("INPR");
static const std::string MARK_RM("RM");
#ifdef __MINGW32__
int pathRowSize = 58;
#else // !__MINGW32__
@ -749,18 +744,18 @@ void RequestGroupMan::showDownloadResults(OutputFile& o, bool full) const
if((*itr)->belongsTo != 0) {
continue;
}
std::string status;
const char* status;
if((*itr)->result == error_code::FINISHED) {
status = MARK_OK;
status = "OK";
++ok;
} else if((*itr)->result == error_code::IN_PROGRESS) {
status = MARK_INPR;
status = "INPR";
++inpr;
} else if((*itr)->result == error_code::REMOVED) {
status = MARK_RM;
status = "RM";
++rm;
} else {
status = MARK_ERR;
status = "ERR";
++err;
}
if(full) {
@ -791,7 +786,7 @@ void RequestGroupMan::showDownloadResults(OutputFile& o, bool full) const
namespace {
void formatDownloadResultCommon
(std::ostream& o,
const std::string& status,
const char* status,
const DownloadResultHandle& downloadResult)
{
o << std::setw(3) << downloadResult->gid << "|"
@ -810,7 +805,7 @@ void formatDownloadResultCommon
void RequestGroupMan::formatDownloadResultFull
(OutputFile& out,
const std::string& status,
const char* status,
const DownloadResultHandle& downloadResult) const
{
BitfieldMan bt(downloadResult->pieceLength, downloadResult->totalLength);
@ -852,7 +847,7 @@ void RequestGroupMan::formatDownloadResultFull
}
std::string RequestGroupMan::formatDownloadResult
(const std::string& status,
(const char* status,
const DownloadResultHandle& downloadResult) const
{
std::stringstream o;

View File

@ -94,11 +94,11 @@ private:
void formatDownloadResultFull
(OutputFile& out,
const std::string& status,
const char* status,
const DownloadResultHandle& downloadResult) const;
std::string formatDownloadResult
(const std::string& status,
(const char* status,
const DownloadResultHandle& downloadResult) const;
void configureRequestGroup

View File

@ -146,7 +146,7 @@ void Sqlite3CookieParser::parse(std::vector<Cookie>& cookies)
}
std::vector<Cookie> tcookies;
char* sqlite3ErrMsg = 0;
int ret = sqlite3_exec(db_, getQuery().c_str(), cookieRowMapper,
int ret = sqlite3_exec(db_, getQuery(), cookieRowMapper,
&tcookies, &sqlite3ErrMsg);
std::string errMsg;
if(sqlite3ErrMsg) {

View File

@ -61,7 +61,7 @@ protected:
// must return 6 columns in the following order: host, path,
// secure(1 for secure, 0 for not), expiry(utc, unix time), name,
// value, last access time(utc, unix time)
virtual const std::string& getQuery() const = 0;
virtual const char* getQuery() const = 0;
private:
sqlite3* db_;
};

View File

@ -41,12 +41,11 @@ Sqlite3MozCookieParser::Sqlite3MozCookieParser(const std::string& filename):
Sqlite3MozCookieParser::~Sqlite3MozCookieParser() {}
const std::string& Sqlite3MozCookieParser::getQuery() const
const char* Sqlite3MozCookieParser::getQuery() const
{
static const std::string sql =
return
"SELECT host, path, isSecure, expiry, name, value, lastAccessed"
" FROM moz_cookies";
return sql;
}
Sqlite3ChromiumCookieParser::Sqlite3ChromiumCookieParser
@ -54,12 +53,11 @@ Sqlite3ChromiumCookieParser::Sqlite3ChromiumCookieParser
Sqlite3ChromiumCookieParser::~Sqlite3ChromiumCookieParser() {}
const std::string& Sqlite3ChromiumCookieParser::getQuery() const
const char* Sqlite3ChromiumCookieParser::getQuery() const
{
static const std::string sql =
return
"SELECT host_key, path, secure, expires_utc, name, value, last_access_utc"
" FROM cookies";
return sql;
}
} // namespace aria2

View File

@ -44,7 +44,7 @@ public:
Sqlite3MozCookieParser(const std::string& filename);
virtual ~Sqlite3MozCookieParser();
protected:
virtual const std::string& getQuery() const;
virtual const char* getQuery() const;
};
class Sqlite3ChromiumCookieParser:public Sqlite3CookieParser {
@ -52,7 +52,7 @@ public:
Sqlite3ChromiumCookieParser(const std::string& filename);
virtual ~Sqlite3ChromiumCookieParser();
protected:
virtual const std::string& getQuery() const;
virtual const char* getQuery() const;
};
} // namespace aria2

View File

@ -240,11 +240,10 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT));
option->put(PREF_REUSE_URI, A2_V_FALSE);
option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE);
static const std::string TRACKER_ANNOUNCE_FILE("[tracker.announce]");
SharedHandle<DownloadContext> dctx
(new DownloadContext(option->getAsInt(PREF_PIECE_LENGTH),
0,
TRACKER_ANNOUNCE_FILE));
"[tracker.announce]"));
dctx->getFileEntries().front()->setUris(uris);
rg->setDownloadContext(dctx);
SharedHandle<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());