Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2013-09-09 13:43:20 +0400
committerKenneth Heafield <github@kheafield.com>2013-09-09 13:43:20 +0400
commit5cca6fafcbf903dc4abcfc86ae83299171633c9d (patch)
tree70880b6f89feebac9b57312b930127f76fca2d15 /util
parent4c015afb7e704477633b3065c72c03e4c9daf794 (diff)
KenLM 6f7913cc7ca0f7672c6d899358365f047a742bbb
Mostly fixes from Tetsuo Kiso and Jonathan Graehl
Diffstat (limited to 'util')
-rw-r--r--util/string_piece.hh12
-rw-r--r--util/usage.cc6
2 files changed, 14 insertions, 4 deletions
diff --git a/util/string_piece.hh b/util/string_piece.hh
index 9cf4c7f6d..84431db17 100644
--- a/util/string_piece.hh
+++ b/util/string_piece.hh
@@ -74,6 +74,12 @@ inline bool operator!=(const StringPiece& x, const StringPiece& y) {
#endif // old version of ICU
U_NAMESPACE_BEGIN
+
+inline bool starts_with(const StringPiece& longer, const StringPiece& prefix) {
+ int longersize = longer.size(), prefixsize = prefix.size();
+ return longersize >= prefixsize && std::memcmp(longer.data(), prefix.data(), prefixsize) == 0;
+}
+
#else
#include <algorithm>
@@ -212,7 +218,7 @@ class StringPiece {
StringPiece substr(size_type pos, size_type n = npos) const;
static int wordmemcmp(const char* p, const char* p2, size_type N) {
- return memcmp(p, p2, N);
+ return std::memcmp(p, p2, N);
}
};
@@ -227,6 +233,10 @@ inline bool operator!=(const StringPiece& x, const StringPiece& y) {
return !(x == y);
}
+inline bool starts_with(const StringPiece& longer, const StringPiece& prefix) {
+ return longer.starts_with(prefix);
+}
+
#endif // HAVE_ICU undefined
inline bool operator<(const StringPiece& x, const StringPiece& y) {
diff --git a/util/usage.cc b/util/usage.cc
index 8db375e14..25fc09755 100644
--- a/util/usage.cc
+++ b/util/usage.cc
@@ -83,7 +83,7 @@ void PrintUsage(std::ostream &out) {
}
struct rusage usage;
- if (getrusage(RUSAGE_CHILDREN, &usage)) {
+ if (getrusage(RUSAGE_SELF, &usage)) {
perror("getrusage");
return;
}
@@ -135,7 +135,7 @@ template <class Num> uint64_t ParseNum(const std::string &arg) {
if (after == "%") {
uint64_t mem = GuessPhysicalMemory();
UTIL_THROW_IF_ARG(!mem, SizeParseError, (arg), "because % was specified but the physical memory size could not be determined.");
- return static_cast<double>(value) * static_cast<double>(mem) / 100.0;
+ return static_cast<uint64_t>(static_cast<double>(value) * static_cast<double>(mem) / 100.0);
}
std::string units("bKMGTPEZY");
@@ -144,7 +144,7 @@ template <class Num> uint64_t ParseNum(const std::string &arg) {
for (std::string::size_type i = 0; i < index; ++i) {
value *= 1024;
}
- return value;
+ return static_cast<uint64_t>(value);
}
} // namespace