From b5ea6727b60a01e51356ddc2cfeeaedd8cd61507 Mon Sep 17 00:00:00 2001 From: "dsites@google.com" Date: Sun, 8 Sep 2013 00:38:49 +0000 Subject: [PATCH] Remove unused sys/time.h, remove snprintf, add casts for sign/unsigned complaints, all Visual C++ git-svn-id: https://cld2.googlecode.com/svn/trunk@78 b252ecd4-b096-bf77-eb8e-91563289f87e --- internal/cldutil_offline.cc | 2 +- internal/compact_lang_det_hint_code.cc | 8 ++++---- internal/compact_lang_det_impl.cc | 1 - internal/debug.cc | 8 ++++---- internal/getonescriptspan.cc | 12 ------------ internal/offsetmap.cc | 12 ++++++------ internal/scoreonescriptspan.cc | 4 ++-- internal/scoreutf8text.cc | 1 - 8 files changed, 17 insertions(+), 31 deletions(-) diff --git a/internal/cldutil_offline.cc b/internal/cldutil_offline.cc index e53c175..4007ea6 100644 --- a/internal/cldutil_offline.cc +++ b/internal/cldutil_offline.cc @@ -68,7 +68,7 @@ uint32 GetNextLangprob(ULScriptRType rtype, uint32 probs = QuadHashV3Lookup4(wrt_quadgram_obj, quadhash); int indirect_subscr = probs & ~wrt_quadgram_obj->kCLDTableKeyMask; uint32 langprob; - if (indirect_subscr < wrt_quadgram_obj->kCLDTableSizeOne) { + if (indirect_subscr < static_cast(wrt_quadgram_obj->kCLDTableSizeOne)) { // Up to three languages at indirect langprob = wrt_quadgram_obj->kCLDTableInd[indirect_subscr]; } else { diff --git a/internal/compact_lang_det_hint_code.cc b/internal/compact_lang_det_hint_code.cc index 345c260..52657ae 100644 --- a/internal/compact_lang_det_hint_code.cc +++ b/internal/compact_lang_det_hint_code.cc @@ -19,7 +19,7 @@ #include "compact_lang_det_hint_code.h" #include // for abs() -#include // for snprintf() +#include // for sprintf() #include // #include "lang_script.h" #include "port.h" @@ -1506,12 +1506,12 @@ void SetCLDLanguageHint(Language lang, CLDLangPriors* langpriors) { } -// Make printable stringof priors +// Make printable string of priors string DumpCLDLangPriors(const CLDLangPriors* langpriors) { string retval; for (int i = 0; i < langpriors->n; ++i) { - char temp[32]; - snprintf(temp, sizeof(temp), "%s.%d ", + char temp[64]; + sprintf(temp, "%s.%d ", LanguageCode(GetCLDPriorLang(langpriors->prior[i])), GetCLDPriorWeight(langpriors->prior[i])); retval.append(temp); diff --git a/internal/compact_lang_det_impl.cc b/internal/compact_lang_det_impl.cc index 5322dc3..1e079c1 100644 --- a/internal/compact_lang_det_impl.cc +++ b/internal/compact_lang_det_impl.cc @@ -18,7 +18,6 @@ #include #include -#include // for gettimeofday #include #include "cldutil.h" diff --git a/internal/debug.cc b/internal/debug.cc index 1a56981..e9d2e1c 100644 --- a/internal/debug.cc +++ b/internal/debug.cc @@ -128,7 +128,7 @@ string GetScoreTxt(const ScoringContext* scoringcontext, const CLD2TableSummary* base_obj, int indirect) { string retval; retval.clear(); - if (indirect < base_obj->kCLDTableSizeOne) { + if (indirect < static_cast(base_obj->kCLDTableSizeOne)) { // Up to three languages at indirect uint32 langprob = base_obj->kCLDTableInd[indirect]; retval.append(GetLangProbTxt(scoringcontext, langprob)); @@ -209,7 +209,7 @@ static int GetTextColor(Language lang, bool lighten) { string GetPlainEscapedText(const string& txt) { string retval; retval.clear(); - for (int i = 0; i < txt.size(); ++i) { + for (int i = 0; i < static_cast(txt.size()); ++i) { char c = txt[i]; if (c == '\n') { retval.append(" "); @@ -225,7 +225,7 @@ string GetPlainEscapedText(const string& txt) { string GetHtmlEscapedText(const string& txt) { string retval; retval.clear(); - for (int i = 0; i < txt.size(); ++i) { + for (int i = 0; i < static_cast(txt.size()); ++i) { char c = txt[i]; if (c == '<') { retval.append("<"); @@ -463,7 +463,7 @@ void CLD2_Debug2(const char* text, void DumpResultChunkVector(FILE* f, const char* src, ResultChunkVector* resultchunkvector) { fprintf(f, "DumpResultChunkVector[%ld]
\n", resultchunkvector->size()); - for (int i = 0; i < resultchunkvector->size(); ++i) { + for (int i = 0; i < static_cast(resultchunkvector->size()); ++i) { ResultChunk* rc = &(*resultchunkvector)[i]; Language lang1 = static_cast(rc->lang1); string this_chunk = string(src, rc->offset, rc->bytes); diff --git a/internal/getonescriptspan.cc b/internal/getonescriptspan.cc index 7fdc34f..7bbb9d7 100644 --- a/internal/getonescriptspan.cc +++ b/internal/getonescriptspan.cc @@ -18,7 +18,6 @@ #include "getonescriptspan.h" -#include // for gettimeofday #include #include "fixunicodevalue.h" @@ -287,14 +286,6 @@ int runetochar(char *str, const char32 *rune) { } -// Convert GetTimeOfDay output to 64-bit usec -static inline uint64 Microseconds(const struct timeval& t) { - // The SumReducer uses uint64, so convert to (uint64) microseconds, - // not (double) seconds. - return t.tv_sec * 1000000ULL + t.tv_usec; -} - - // Useful for converting an entity to an ascii value. // RETURNS unicode value, or -1 if entity isn't valid. Don't include & or ; @@ -844,7 +835,6 @@ bool ScriptScanner::GetOneScriptSpan(LangSpan* span) { map2original_.Clear(); map2original_.Delete(span->offset); // So that MapBack(0) gives offset - // gettimeofday(&script_start, NULL); // Get to the first real non-tag letter or entity that is a letter int skip = SkipToFrontOfSpan(next_byte_, byte_length_, &spanscript); next_byte_ += skip; @@ -861,8 +851,6 @@ bool ScriptScanner::GetOneScriptSpan(LangSpan* span) { return false; // No more letters to be found } - // gettimeofday(&script_mid, NULL); - // There is at least one letter, so we know the script for this span span->ulscript = (ULScript)spanscript; diff --git a/internal/offsetmap.cc b/internal/offsetmap.cc index b6db991..84609a7 100644 --- a/internal/offsetmap.cc +++ b/internal/offsetmap.cc @@ -80,7 +80,7 @@ void OffsetMap::Printmap(const char* filename) { Flush(); // Make sure any pending entry gets printed fprintf(fout, "Offsetmap: %ld bytes\n", diffs_.size()); - for (int i = 0; i < diffs_.size(); ++i) { + for (int i = 0; i < static_cast(diffs_.size()); ++i) { fprintf(fout, "%c%02d ", "&=+-"[OpPart(diffs_[i])], LenPart(diffs_[i])); if ((i % 20) == 19) {fprintf(fout, "\n");} } @@ -206,7 +206,7 @@ void OffsetMap::Emit(MapOp op, int len) { } void OffsetMap::DumpString() { - for (int i = 0; i < diffs_.size(); ++i) { + for (int i = 0; i < static_cast(diffs_.size()); ++i) { fprintf(stderr, "%c%02d ", "&=+-"[OpPart(diffs_[i])], LenPart(diffs_[i])); } fprintf(stderr, "\n"); @@ -216,7 +216,7 @@ void OffsetMap::DumpString() { int aoffset = 0; int aprimeoffset = 0; int length = 0; - for (int i = 0; i < diffs_.size(); ++i) { + for (int i = 0; i < static_cast(diffs_.size()); ++i) { char c = diffs_[i]; MapOp op = static_cast(OpPart(c)); int len = LenPart(c); @@ -317,7 +317,7 @@ int OffsetMap::ParseNext(int sub, MapOp* op, int* length) { *op = PREFIX_OP; *length = 0; char c; - while ((sub < diffs_.size()) && (*op == PREFIX_OP)) { + while ((sub < static_cast(diffs_.size())) && (*op == PREFIX_OP)) { c = diffs_[sub++]; *op = static_cast(OpPart(c)); int len = LenPart(c); @@ -339,7 +339,7 @@ int OffsetMap::ParsePrevious(int sub, MapOp* op, int* length) { void OffsetMap::PrintPosition(const char* str) { MapOp op = PREFIX_OP; int length = 0; - if ((0 < next_diff_sub_) && (next_diff_sub_ <= diffs_.size())) { + if ((0 < next_diff_sub_) && (next_diff_sub_ <= static_cast(diffs_.size()))) { op = static_cast(OpPart(diffs_[next_diff_sub_ - 1])); length = LenPart(diffs_[next_diff_sub_ - 1]); } @@ -354,7 +354,7 @@ void OffsetMap::PrintPosition(const char* str) { // Return true if move was OK bool OffsetMap::MoveRight() { // If at last range or RIGHT, set to RIGHT, return error - if (next_diff_sub_ >= diffs_.size()) { + if (next_diff_sub_ >= static_cast(diffs_.size())) { SetRight(); return false; } diff --git a/internal/scoreonescriptspan.cc b/internal/scoreonescriptspan.cc index a581885..da07fb7 100644 --- a/internal/scoreonescriptspan.cc +++ b/internal/scoreonescriptspan.cc @@ -184,7 +184,7 @@ void GetTextSpanOffsets(const ScoringHitBuffer* hitbuffer, int DiffScore(const CLD2TableSummary* obj, int indirect, uint16 lang1, uint16 lang2) { - if (indirect < obj->kCLDTableSizeOne) { + if (indirect < static_cast(obj->kCLDTableSizeOne)) { // Up to three languages at indirect uint32 langprob = obj->kCLDTableInd[indirect]; return GetLangScore(langprob, lang1) - GetLangScore(langprob, lang2); @@ -914,7 +914,7 @@ void LinearizeAll(ScoringContext* scoringcontext, bool score_cjk, ++base_i; // One langprob in kQuadInd[0..SingleSize), // two in kQuadInd[SingleSize..Size) - if (indirect < base_obj->kCLDTableSizeOne) { + if (indirect < static_cast(base_obj->kCLDTableSizeOne)) { // Up to three languages at indirect uint32 langprob = base_obj->kCLDTableInd[indirect]; if (langprob > 0) { diff --git a/internal/scoreutf8text.cc b/internal/scoreutf8text.cc index 294a475..16fe6d8 100644 --- a/internal/scoreutf8text.cc +++ b/internal/scoreutf8text.cc @@ -22,7 +22,6 @@ #include // for sqrt #include #include -#include // for gettimeofday #include #include "debug.h" // for uint8 etc