diff options
Diffstat (limited to 'searchlib')
31 files changed, 436 insertions, 264 deletions
diff --git a/searchlib/src/vespa/searchlib/bitcompression/compression.cpp b/searchlib/src/vespa/searchlib/bitcompression/compression.cpp index 2aa21f9871d..54e32c022b5 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/compression.cpp +++ b/searchlib/src/vespa/searchlib/bitcompression/compression.cpp @@ -17,9 +17,9 @@ CodingTables::CodingTables() unsigned int x; uint8_t log2Val; - for(x=0; x<65536; x++) { + for (x=0; x<65536; x++) { unsigned int val = x; - for (log2Val = 0; (val >>= 1) != 0; log2Val++); + for (log2Val = 0; (val >>= 1) != 0; log2Val++) { } _log2Table[x] = log2Val; } } @@ -139,8 +139,9 @@ readBytes(uint8_t *buf, size_t len) { while (len > 0) { // Ensure that buffer to read from isn't empty - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _readContext->readComprBuffer(); + } uint64_t readOffset = getReadOffset(); // Validate that read offset is byte aligned assert((readOffset & 7) == 0); @@ -159,8 +160,9 @@ readBytes(uint8_t *buf, size_t len) // Adjust read position to account for bytes read _readContext->setPosition(readOffset + copySize * 8); } - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _readContext->readComprBuffer(); + } } @@ -272,8 +274,9 @@ writeString(vespalib::stringref buf) size_t len = buf.size(); for (unsigned int i = 0; i < len; ++i) { writeBits(static_cast<unsigned char>(buf[i]), 8); - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } } writeBits(0, 8); } diff --git a/searchlib/src/vespa/searchlib/bitcompression/compression.h b/searchlib/src/vespa/searchlib/bitcompression/compression.h index c6b3c4de3a2..67e23aabc1e 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/compression.h +++ b/searchlib/src/vespa/searchlib/bitcompression/compression.h @@ -172,8 +172,9 @@ public: } \ val64 = (val >> (63 - olength - (k))) - (UINT64_C(1) << (k)); \ val <<= olength + 1 + (k); \ - if (__builtin_expect(olength + 1 + (k) == 64, false)) \ + if (__builtin_expect(olength + 1 + (k) == 64, false)) { \ val = 0; \ + } \ length += olength + 1 + (k); \ UC64BE_READBITS(val, valI, preRead, cacheInt, EC); \ } while (0) @@ -236,8 +237,9 @@ public: length = 0; \ } \ val <<= olength + 1 + (k); \ - if (__builtin_expect(olength + 1 + (k) == 64, false)) \ + if (__builtin_expect(olength + 1 + (k) == 64, false)) { \ val = 0; \ + } \ length += olength + 1 + (k); \ UC64BE_READBITS(val, valI, preRead, cacheInt, EC); \ } while (0) @@ -393,8 +395,9 @@ public: ::search::bitcompression::EncodeContext64LE::ffsl(val); \ length = olength + 1; \ val >>= length; \ - if (__builtin_expect(length == 64, false)) \ + if (__builtin_expect(length == 64, false)) { \ val = 0; \ + } \ if (__builtin_expect(olength * 2 + 1 + (k) > 64, false)) { \ UC64LE_READBITS(val, valI, preRead, cacheInt, EC); \ length = 0; \ @@ -459,8 +462,9 @@ public: ::search::bitcompression::EncodeContext64LE::ffsl(val); \ length = olength + 1; \ val >>= length; \ - if (__builtin_expect(length == 64, false)) \ + if (__builtin_expect(length == 64, false)) { \ val = 0; \ + } \ if (__builtin_expect(olength * 2 + 1 + (k) > 64, false)) { \ UC64LE_READBITS(val, valI, preRead, cacheInt, EC); \ length = 0; \ @@ -897,8 +901,9 @@ public: } void smallPadBits(uint32_t length) { - if (length > 0) + if (length > 0) { writeBits(0, length); + } } virtual void padBits(uint32_t length) { @@ -970,18 +975,20 @@ public: uint32_t upper32 = lower >> 32; if (upper32 != 0) { uint32_t upper16 = upper32 >> 16; - if (upper16 != 0) + if (upper16 != 0) { retVal = 48 + CodingTables::_log2Table[upper16]; - else + } else { retVal = 32 + CodingTables::_log2Table[upper32]; + } } else { uint32_t lower32 = static_cast<uint32_t>(x); uint32_t upper16 = lower32 >> 16; - if (upper16 != 0) + if (upper16 != 0) { retVal = 16 + CodingTables::_log2Table[upper16]; - else + } else { retVal = CodingTables::_log2Table[lower32]; + } } #endif @@ -1010,9 +1017,9 @@ public: uint32_t log2qx2 = asmlog2((x >> k) + 1) * 2; uint64_t expGolomb = x + (UINT64_C(1) << k); - if (log2qx2 < 64 - k) + if (log2qx2 < 64 - k) { writeBits(expGolomb, k + log2qx2 + 1); - else { + } else { writeBits(0, k + log2qx2 + 1 - 64); writeBits(expGolomb, 64); } @@ -1022,9 +1029,9 @@ public: uint64_t expGolomb = x + (UINT64_C(1) << k) - (UINT64_C(1) << (k + log2q)); - if (log2qx2 < 64 - k) + if (log2qx2 < 64 - k) { writeBits(((expGolomb << 1) | 1) << log2q, k + log2qx2 + 1); - else { + } else { writeBits(0, log2q); writeBits((expGolomb << 1) | 1, log2q + k + 1); } @@ -1055,10 +1062,12 @@ public: static uint32_t encodeDExpGolombSpace(uint64_t x, uint32_t k) { - if (x == 0) + if (x == 0) { return 1; - if (x == 1) + } + if (x == 1) { return 2; + } return 2 + encodeExpGolombSpace(x, k); } @@ -1076,18 +1085,20 @@ public: static uint32_t encodeD0ExpGolombSpace(uint64_t x, uint32_t k) { - if (x == 0) + if (x == 0) { return 1; + } return 1 + encodeExpGolombSpace(x, k); } static uint64_t convertToUnsigned(int64_t val) { - if (val < 0) + if (val < 0) { return ((- val) << 1) - 1; - else + } else { return (val << 1); + } } }; @@ -1206,9 +1217,9 @@ public: uint64_t getBitPos(int bitOffset, uint64_t bufferEndFilePos) const override { int intOffset = _realValE - _valI; - if (bitOffset == -1) + if (bitOffset == -1) { bitOffset = -64 - _preRead; - + } return (bufferEndFilePos << 3) - (static_cast<uint64_t>(intOffset) << 6) + bitOffset; } @@ -1245,10 +1256,11 @@ public: */ void setEnd(unsigned int unitCount, bool moreData) { _valE = _realValE = _valI + unitCount; - if (moreData) + if (moreData) { _valE -= END_BUFFER_SAFETY; - else + } else { _valE += END_BUFFER_SAFETY; + } } const uint64_t *getCompr() const { @@ -1260,10 +1272,11 @@ public: } static int64_t convertToSigned(uint64_t val) { - if ((val & 1) != 0) + if ((val & 1) != 0) { return - (val >> 1) - 1; - else + } else { return (val >> 1); + } } }; @@ -1364,10 +1377,11 @@ public: cacheInt = EC::bswap(*valI++); preRead = 64 - length; - if (bigEndian) + if (bigEndian) { val |= (cacheInt >> preRead); - else + } else { val |= (cacheInt << preRead); + } }; void skipBits(int bits) override { @@ -1377,10 +1391,11 @@ public: bits -= 64; } if (bits > 0) { - if (bigEndian) + if (bigEndian) { _val <<= bits; - else + } else { _val >>= bits; + } ReadBits(bits, _val, _cacheInt, _preRead, _valI); } } @@ -1448,8 +1463,9 @@ public: (void) readBits(64); pad -= 64; } - if (pad > 0) + if (pad > 0) { (void) readBits(pad); + } } /* @@ -1459,8 +1475,9 @@ public: smallAlign(uint32_t alignment) { uint64_t pad = _preRead & (alignment - 1); - if (pad > 0) + if (pad > 0) { (void) readBits(pad); + } } }; @@ -1538,8 +1555,9 @@ public: void readComprBufferIfNeeded() { - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { readComprBuffer(); + } } void @@ -1586,10 +1604,11 @@ public: readComprBufferIfNeeded(); } if (bits > 0) { - if (bigEndian) + if (bigEndian) { _val <<= bits; - else + } else { _val >>= bits; + } ReadBits(bits, _val, _cacheInt, _preRead, _valI); readComprBufferIfNeeded(); } @@ -1605,8 +1624,9 @@ public: pad -= 64; readComprBufferIfNeeded(); } - if (pad > 0) + if (pad > 0) { (void) readBits(pad); + } readComprBufferIfNeeded(); } }; @@ -1674,8 +1694,9 @@ public: void writeComprBufferIfNeeded() { - if (_valI >= _valE) + if (_valI >= _valE) { _writeContext->writeComprBuffer(false); + } } void diff --git a/searchlib/src/vespa/searchlib/bitcompression/countcompression.cpp b/searchlib/src/vespa/searchlib/bitcompression/countcompression.cpp index b0da806286e..e0be7e9b890 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/countcompression.cpp +++ b/searchlib/src/vespa/searchlib/bitcompression/countcompression.cpp @@ -85,8 +85,9 @@ readCounts(PostingListCounts &counts) } } UC64_DECODECONTEXT_STORE(o, _); - if (__builtin_expect(oCompr >= valE, false)) + if (__builtin_expect(oCompr >= valE, false)) { _readContext->readComprBuffer(); + } } void @@ -110,8 +111,9 @@ writeCounts(const PostingListCounts &counts) assert(numDocs > 0); encodeExpGolomb(numDocs - 1, K_VALUE_COUNTFILE_SPNUMDOCS); if (numDocs == 0) { - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } return; } uint64_t encodeVal = counts._bitLength; @@ -119,8 +121,9 @@ writeCounts(const PostingListCounts &counts) uint32_t kVal = (expVal < 4) ? 1 : asmlog2(expVal); encodeExpGolomb(encodeVal, kVal); uint32_t numChunks = counts._segments.size(); - if (numDocs >= _minChunkDocs) + if (numDocs >= _minChunkDocs) { encodeExpGolomb(numChunks, K_VALUE_COUNTFILE_NUMCHUNKS); + } if (numChunks != 0) { typedef std::vector<PostingListCounts::Segment>::const_iterator segit; @@ -128,8 +131,9 @@ writeCounts(const PostingListCounts &counts) uint32_t prevLastDoc = 0u; for (segit it = counts._segments.begin(); it != ite; ++it) { - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } encodeExpGolomb(it->_numDocs - 1, K_VALUE_COUNTFILE_CHUNKNUMDOCS); encodeExpGolomb(it->_bitLength, @@ -139,8 +143,9 @@ writeCounts(const PostingListCounts &counts) prevLastDoc = it->_lastDoc; } } - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } } void diff --git a/searchlib/src/vespa/searchlib/bitcompression/pagedict4.cpp b/searchlib/src/vespa/searchlib/bitcompression/pagedict4.cpp index 77a6d5bd86b..85b6df7af12 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/pagedict4.cpp +++ b/searchlib/src/vespa/searchlib/bitcompression/pagedict4.cpp @@ -106,11 +106,9 @@ getLCP(vespalib::stringref word, size_t len2 = prevWord.size(); size_t res = 0; - while (res < len1 && - res < len2 && - res < 254u && - word[res] == prevWord[res]) + while (res < len1 && res < len2 && res < 254u && word[res] == prevWord[res]) { ++res; + } return res; } @@ -488,13 +486,13 @@ PageDict4SPWriter::addL3Skip(vespalib::stringref word, _l3WordNum = wordNum; ++_l3Entries; ++_l4StrideCheck; - if (_l4StrideCheck >= getL4SkipStride()) + if (_l4StrideCheck >= getL4SkipStride()) { addL4Skip(lcp); + } addLCPWord(word, lcp, _words); _l3WordOffset = _words.size(); _l3PageNum = pageNum; - if (_l3Size + _l4Size + _l5Size + _headerSize + 8 * _l3WordOffset > - getPageBitSize()) { + if (_l3Size + _l4Size + _l5Size + _headerSize + 8 * _l3WordOffset > getPageBitSize()) { // Cannot convert tentative writes to full writes due to overflow. // Flush existing full writes. flushPage(); @@ -518,8 +516,9 @@ PageDict4SPWriter::addL4Skip(size_t &lcp) { size_t tlcp = getLCP(_l3Word, _l4Word); assert(tlcp <= lcp); - if (tlcp < lcp) + if (tlcp < lcp) { lcp = tlcp; + } _l4StrideCheck = 0u; _eL4.encodeExpGolomb(_l3WordOffset - _l4WordOffset, K_VALUE_COUNTFILE_L4_WORDOFFSET); @@ -554,8 +553,9 @@ PageDict4SPWriter::addL5Skip(size_t &lcp) { size_t tlcp = getLCP(_l3Word, _l5Word); assert(tlcp <= lcp); - if (tlcp < lcp) + if (tlcp < lcp) { lcp = tlcp; + } _eL5.encodeExpGolomb(_l3WordOffset - _l5WordOffset, K_VALUE_COUNTFILE_L5_WORDOFFSET); _eL5.writeComprBufferIfNeeded(); @@ -774,10 +774,12 @@ addCounts(vespalib::stringref word, { assert(_countsWordOffset == _words.size()); size_t lcp = getLCP(_pendingCountsWord, _countsWord); - if (_l1StrideCheck >= getL1SkipStride()) + if (_l1StrideCheck >= getL1SkipStride()) { addL1Skip(lcp); - if (_countsEntries > 0) + } + if (_countsEntries > 0) { addLCPWord(_pendingCountsWord, lcp, _words); + } _eCounts.writeCounts(counts); uint32_t eCountsOffset = static_cast<uint32_t>(_eCounts.getWriteOffset()); if (eCountsOffset + _l1Size + _l2Size + _headerSize + @@ -863,8 +865,9 @@ PageDict4PWriter::addL1Skip(size_t &lcp) _prevL2Size = _l2Size; // Prepare for undo size_t tlcp = getLCP(_pendingCountsWord, _l1Word); assert(tlcp <= lcp); - if (tlcp < lcp) + if (tlcp < lcp) { lcp = tlcp; + } _l1StrideCheck = 0u; _eL1.encodeExpGolomb(_countsWordOffset - _l1WordOffset, K_VALUE_COUNTFILE_L1_WORDOFFSET); @@ -881,8 +884,9 @@ PageDict4PWriter::addL1Skip(size_t &lcp) _curCountOffsetL1 = _countsSize; _l1Size = _eL1.getWriteOffset(); ++_l2StrideCheck; - if (_l2StrideCheck >= getL2SkipStride()) + if (_l2StrideCheck >= getL2SkipStride()) { addL2Skip(lcp); + } _l1WordOffset = _countsWordOffset + 2 + _pendingCountsWord.size() - lcp; } @@ -892,8 +896,9 @@ PageDict4PWriter::addL2Skip(size_t &lcp) { size_t tlcp = getLCP(_pendingCountsWord, _l2Word); assert(tlcp <= lcp); - if (tlcp < lcp) + if (tlcp < lcp) { lcp = tlcp; + } _l2StrideCheck = 0; _eL2.encodeExpGolomb(_countsWordOffset - _l2WordOffset, K_VALUE_COUNTFILE_L2_WORDOFFSET); @@ -1026,8 +1031,9 @@ PageDict4SSReader::setup(DC &ssd) if (l7StrideCheck >= getL7SkipStride() || (l7StrideCheck > 0 && (overflow || forceL7Entry))) { // Don't update l7Ref if this L7 entry points to an overflow entry - if (!forceL7Entry) + if (!forceL7Entry) { l7Ref = _l7.size(); // Self-ref if referencing L6 entry + } _l7.push_back(L7Entry(word, startOffset, l6WordNum, l6Offset, sparsePageNum, pageNum, l7Ref)); l7StrideCheck = 0; @@ -1069,8 +1075,9 @@ PageDict4SSReader::setup(DC &ssd) l6Offset = dL6.getReadOffset(); } if (l7StrideCheck > 0) { - if (!forceL7Entry) + if (!forceL7Entry) { l7Ref = _l7.size(); // Self-ref if referencing L6 entry + } _l7.push_back(L7Entry(word, startOffset, l6WordNum, l6Offset, sparsePageNum, pageNum, l7Ref)); } @@ -1185,8 +1192,9 @@ lookup(vespalib::stringref key) LOG_ABORT("FATAL: Missing L7 entry for overflow entry"); // counts < key, should not happen (missing L7 entry) } else { bool l6NotLessThanKey = !(word < key); - if (l6NotLessThanKey) + if (l6NotLessThanKey) { break; // key <= counts + } UC64_DECODECONTEXT_LOAD(o, dL6._); UC64_DECODEEXPGOLOMB_NS(o, K_VALUE_COUNTFILE_L6_PAGENUM, @@ -1202,10 +1210,11 @@ lookup(vespalib::stringref key) } assert(l6Offset <= _ssFileBitLen); res._l6Word = l6Word; - if (l6Offset >= _ssFileBitLen) + if (l6Offset >= _ssFileBitLen) { res._lastWord.clear(); // Mark that word is beyond end of dictionary - else + } else { res._lastWord = word; + } res._l6StartOffset = l6StartOffset; res._pageNum = pageNum; res._sparsePageNum = sparsePageNum; @@ -1342,8 +1351,9 @@ lookup(const SSReader &ssReader, dL4.copyParams(ssReader.getSSD()); dL5.copyParams(ssReader.getSSD()); uint32_t spStartOffset = 0; - if (l6WordNum == 1) + if (l6WordNum == 1) { spStartOffset = ssReader._spFirstPageOffset; + } setDecoderPositionInPage(dL5, sparsePage, spStartOffset); uint32_t l5Size = dL5.readBits(15); @@ -1390,8 +1400,9 @@ lookup(const SSReader &ssReader, assert(lcp <= _l3Word.size()); word = _l3Word.substr(0, lcp) + l5WordBuf; bool l3NotLessThanKey = !(word < key); - if (l3NotLessThanKey) + if (l3NotLessThanKey) { break; + } _l3Word = word; l3WordOffset = l5WordOffset + 2 + word.size() - lcp; l5WordOffset = l3WordOffset; @@ -1432,8 +1443,9 @@ lookup(const SSReader &ssReader, assert(lcp <= _l3Word.size()); word = _l3Word.substr(0, lcp) + l4WordBuf; bool l3NotLessThanKey = !(word < key); - if (l3NotLessThanKey) + if (l3NotLessThanKey) { break; + } _l3Word = word; l3WordOffset = l4WordOffset + 2 + word.size() - lcp; l4WordOffset = l3WordOffset; @@ -1464,16 +1476,18 @@ lookup(const SSReader &ssReader, assert(lcp <= _l3Word.size()); word = _l3Word.substr(0, lcp) + l3WordBuf; bool l3NotLessThanKey = !(word < key); - if (l3NotLessThanKey) + if (l3NotLessThanKey) { break; + } _l3Word = word; l3WordOffset += 2 + word.size() - lcp; } else { word = lastSPWord; assert(!word.empty()); // Should've stopped at SS level bool l3NotLessThanKey = !(word < key); - if (l3NotLessThanKey) + if (l3NotLessThanKey) { break; + } LOG_ABORT("should not be reached"); _l3Word = word; } @@ -1538,8 +1552,9 @@ lookup(const SSReader &ssReader, dL2.copyParams(ssReader.getSSD()); uint32_t pStartOffset = 0; - if (l3WordNum == 1) + if (l3WordNum == 1) { pStartOffset = ssReader._pFirstPageOffset; + } setDecoderPositionInPage(dL2, page, pStartOffset); uint32_t l2Size = dL2.readBits(15); @@ -1596,8 +1611,9 @@ lookup(const SSReader &ssReader, assert(lcp <= countsWord.size()); word = countsWord.substr(0, lcp) + l2WordBuf; bool countsNotLessThanKey = !(word < key); - if (countsNotLessThanKey) + if (countsNotLessThanKey) { break; + } countsWord = word; countsWordOffset = l2WordOffset + 2 + word.size() - lcp; l2WordOffset = countsWordOffset; @@ -1636,8 +1652,9 @@ lookup(const SSReader &ssReader, assert(lcp <= countsWord.size()); word = countsWord.substr(0, lcp) + l1WordBuf; bool countsNotLessThanKey = !(word < key); - if (countsNotLessThanKey) + if (countsNotLessThanKey) { break; + } countsWord = word; countsWordOffset = l1WordOffset + 2 + word.size() - lcp; l1WordOffset = countsWordOffset; @@ -1668,16 +1685,18 @@ lookup(const SSReader &ssReader, assert(lcp <= countsWord.size()); word = countsWord.substr(0, lcp) + countsWordBuf; bool countsNotLessThanKey = !(word < key); - if (countsNotLessThanKey) + if (countsNotLessThanKey) { break; + } countsWordOffset += 2 + word.size() - lcp; countsWord = word; } else { word = lastPWord; assert(!word.empty()); // Should've stopped at SS level bool countsNotLessThanKey = !(word < key); - if (countsNotLessThanKey) + if (countsNotLessThanKey) { break; + } } countsStartOffset.adjust(counts); ++wordNum; @@ -2155,10 +2174,11 @@ PageDict4Reader::readCounts(vespalib::string &word, } } else { assert(_l3Residue > 0); - if (_l3Residue > 1) + if (_l3Residue > 1) { decodeSPWord(word); - else + } else { decodeSSWord(word); + } _lastWord = word; --_l3Residue; } @@ -2180,10 +2200,11 @@ PageDict4Reader::readCounts(vespalib::string &word, _overflowPage = false; assert(_l3Residue > 0); vespalib::string tword; - if (_l3Residue > 1) + if (_l3Residue > 1) { decodeSPWord(tword); - else + } else { decodeSSWord(tword); + } assert(tword == word); --_l3Residue; _lastWord = word; diff --git a/searchlib/src/vespa/searchlib/bitcompression/posocccompression.cpp b/searchlib/src/vespa/searchlib/bitcompression/posocccompression.cpp index 442304de6c9..d4f663f32cc 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/posocccompression.cpp +++ b/searchlib/src/vespa/searchlib/bitcompression/posocccompression.cpp @@ -111,8 +111,9 @@ PosOccFieldParams::setParams(const PostingListParams ¶ms, uint32_t idx) } } params.get(avgElemLenStr, _avgElemLen); - if (params.isSet(nameStr)) + if (params.isSet(nameStr)) { _name = params.getStr(nameStr); + } } @@ -244,8 +245,9 @@ PosOccFieldsParams::getParams(PostingListParams ¶ms) const assert(_numFields == 1u); // Only single field for now params.set("numFields", _numFields); // Single posting file index format will have multiple fields in file - for (uint32_t field = 0; field < _numFields; ++field) + for (uint32_t field = 0; field < _numFields; ++field) { _fieldParams[field].getParams(params, field); + } } @@ -259,8 +261,9 @@ PosOccFieldsParams::setParams(const PostingListParams ¶ms) _params.resize(numFields); cacheParamsRef(); // Single posting file index format will have multiple fields in file - for (uint32_t field = 0; field < numFields; ++field) + for (uint32_t field = 0; field < numFields; ++field) { _params[field].setParams(params, field); + } } @@ -274,8 +277,9 @@ PosOccFieldsParams::setSchemaParams(const Schema &schema, _params.resize(1u); cacheParamsRef(); const Schema::IndexField &field = schema.getIndexField(indexId); - if (!SchemaUtil::validateIndexField(field)) + if (!SchemaUtil::validateIndexField(field)) { LOG_ABORT("should not be reached"); + } _params[0].setSchemaParams(schema, indexId); } @@ -524,8 +528,9 @@ readFeatures(search::index::DocIdAndFeatures &features) } } UC64_DECODECONTEXT_STORE(o, _); - if (__builtin_expect(oCompr >= valE, false)) + if (__builtin_expect(oCompr >= valE, false)) { _readContext->readComprBuffer(); + } } @@ -765,8 +770,9 @@ writeFeatures(const search::index::DocIdAndFeatures &features) encodeExpGolomb(this->convertToUnsigned(elementWeight), K_VALUE_POSOCC_ELEMENTWEIGHT); } - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } } else { uint32_t elementId = element->getElementId(); assert(elementId == 0); @@ -786,8 +792,9 @@ writeFeatures(const search::index::DocIdAndFeatures &features) wordPos = position->getWordPos(); encodeExpGolomb(wordPos - lastWordPos - 1, K_VALUE_POSOCC_FIRST_WORDPOS); - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } ++position; } while (0); uint32_t positionResidue = numPositions - 1; @@ -796,8 +803,9 @@ writeFeatures(const search::index::DocIdAndFeatures &features) wordPos = position->getWordPos(); encodeExpGolomb(wordPos - lastWordPos - 1, K_VALUE_POSOCC_DELTA_WORDPOS); - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } ++position; --positionResidue; } @@ -865,8 +873,7 @@ readFeatures(search::index::DocIdAndFeatures &features) EC); numElements = static_cast<uint32_t>(val64) + 1; } - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone) { if (fieldParams._hasElements) { UC64_SKIPEXPGOLOMB_SMALL_NS(o, K_VALUE_POSOCC_ELEMENTID, @@ -958,8 +965,7 @@ readFeatures(search::index::DocIdAndFeatures &features) numElements = static_cast<uint32_t>(val64) + 1; } uint32_t elementId = 0; - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone, ++elementId) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone, ++elementId) { if (fieldParams._hasElements) { UC64_DECODEEXPGOLOMB_SMALL_NS(o, K_VALUE_POSOCC_ELEMENTID, @@ -1014,8 +1020,9 @@ readFeatures(search::index::DocIdAndFeatures &features) } } UC64_DECODECONTEXT_STORE(o, _); - if (__builtin_expect(oCompr >= valE, false)) + if (__builtin_expect(oCompr >= valE, false)) { _readContext->readComprBuffer(); + } } @@ -1040,8 +1047,7 @@ skipFeatures(unsigned int count) EC); numElements = static_cast<uint32_t>(val64) + 1; } - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone) { if (fieldParams._hasElements) { UC64_SKIPEXPGOLOMB_SMALL_NS(o, K_VALUE_POSOCC_ELEMENTID, @@ -1099,8 +1105,7 @@ unpackFeatures(const search::fef::TermFieldMatchDataArray &matchData, TermFieldMatchData *tfmd = matchData[0]; tfmd->reset(docId); uint32_t elementId = 0; - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone, ++elementId) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone, ++elementId) { int32_t elementWeight = 1; if (fieldParams._hasElements) { UC64_DECODEEXPGOLOMB_SMALL_NS(o, @@ -1247,8 +1252,7 @@ writeFeatures(const search::index::DocIdAndFeatures &features) assert(numElements == 1); } uint32_t minElementId = 0; - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone, ++element) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone, ++element) { if (fieldParams._hasElements) { uint32_t elementId = element->getElementId(); assert(elementId >= minElementId); @@ -1260,8 +1264,9 @@ writeFeatures(const search::index::DocIdAndFeatures &features) encodeExpGolomb(this->convertToUnsigned(elementWeight), K_VALUE_POSOCC_ELEMENTWEIGHT); } - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } } else { uint32_t elementId = element->getElementId(); assert(elementId == 0); @@ -1282,8 +1287,9 @@ writeFeatures(const search::index::DocIdAndFeatures &features) wordPos = position->getWordPos(); encodeExpGolomb(wordPos - lastWordPos - 1, wordPosK); - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { _writeContext->writeComprBuffer(false); + } ++position; --positionResidue; } diff --git a/searchlib/src/vespa/searchlib/bitcompression/posocccompression.h b/searchlib/src/vespa/searchlib/bitcompression/posocccompression.h index e6ff98da9c9..a5d46045ec5 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/posocccompression.h +++ b/searchlib/src/vespa/searchlib/bitcompression/posocccompression.h @@ -40,8 +40,7 @@ public: uint32_t elementLen) { assert(wordPos < elementLen); - if (_elements.empty() || - elementId > _elements.back().getElementId()) { + if (_elements.empty() || elementId > _elements.back().getElementId()) { _elements.emplace_back(elementId, elementWeight, elementLen); } else { assert(elementId == _elements.back().getElementId()); diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp index 3d7550c9c26..398a08da490 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp @@ -62,10 +62,12 @@ BitVectorIdxFileWrite::open(const vespalib::string &name, assert( !_idxFile); _idxFile = std::make_unique<Fast_BufferedFile>(new FastOS_File()); - if (tuneFileWrite.getWantSyncWrites()) + if (tuneFileWrite.getWantSyncWrites()) { _idxFile->EnableSyncWrites(); - if (tuneFileWrite.getWantDirectIO()) + } + if (tuneFileWrite.getWantDirectIO()) { _idxFile->EnableDirectIO(); + } // XXX no checking for success: _idxFile->OpenWriteOnly(idxname.c_str()); diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h index 671ee88e85b..90e5d811479 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h @@ -51,10 +51,12 @@ public: static uint32_t getBitVectorLimit(uint32_t docIdLimit) { // Must match FastS_BinSizeParams::CalcMaxBinSize() uint32_t ret = (docIdLimit + 63) / 64; - if (ret < 16) + if (ret < 16) { ret = 16; - if (ret > docIdLimit) + } + if (ret > docIdLimit) { ret = docIdLimit; + } return ret; } diff --git a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp index 34f42b03a58..4386ee3cd6b 100644 --- a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp @@ -39,8 +39,9 @@ DictionaryWordReader::open(const vespalib::string & dictionaryName, _wordNum = noWordNum(); // Make a mapping from old to new wordID - if (tuneFileRead.getWantDirectIO()) + if (tuneFileRead.getWantDirectIO()) { _old2newwordfile->EnableDirectIO(); + } // no checking possible _old2newwordfile->WriteOpen(wordMapName.c_str()); _old2newwordfile->SetSize(0); @@ -51,8 +52,9 @@ DictionaryWordReader::open(const vespalib::string & dictionaryName, void DictionaryWordReader::close() { - if (!_dictFile->close()) + if (!_dictFile->close()) { LOG(error, "Error closing input dictionary"); + } _old2newwordfile->Flush(); _old2newwordfile->Sync(); _old2newwordfile->Close(); diff --git a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.h b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.h index 9c8db85bbeb..5ee84cc4503 100644 --- a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.h +++ b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.h @@ -63,10 +63,12 @@ public: } bool operator<(const DictionaryWordReader &rhs) const { - if (!isValid()) + if (!isValid()) { return false; - if (!rhs.isValid()) + } + if (!rhs.isValid()) { return true; + } return _word < rhs._word; } diff --git a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp index 90c6970c476..d71ddc2c2d6 100644 --- a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp @@ -136,8 +136,7 @@ DiskIndex::openField(const vespalib::string &fieldDir, } bDict.reset(new BitVectorDictionary()); - if (!bDict->open(fieldDir, tuneFileSearch._read, - BitVectorKeyScope::PERFIELD_WORDS)) { + if (!bDict->open(fieldDir, tuneFileSearch._read, BitVectorKeyScope::PERFIELD_WORDS)) { LOG(warning, "Could not open bit vector dictionary in '%s'", fieldDir.c_str()); @@ -152,13 +151,15 @@ DiskIndex::openField(const vespalib::string &fieldDir, bool DiskIndex::setup(const TuneFileSearch &tuneFileSearch) { - if (!loadSchema() || !openDictionaries(tuneFileSearch)) + if (!loadSchema() || !openDictionaries(tuneFileSearch)) { return false; + } for (SchemaUtil::IndexIterator itr(_schema); itr.isValid(); ++itr) { vespalib::string fieldDir = _indexDir + "/" + itr.getName() + "/"; - if (!openField(fieldDir, tuneFileSearch)) + if (!openField(fieldDir, tuneFileSearch)) { return false; + } } _tuneFileSearch = tuneFileSearch; return true; @@ -169,23 +170,26 @@ bool DiskIndex::setup(const TuneFileSearch &tuneFileSearch, const DiskIndex &old) { - if (tuneFileSearch != old._tuneFileSearch) + if (tuneFileSearch != old._tuneFileSearch) { return setup(tuneFileSearch); - if (!loadSchema() || !openDictionaries(tuneFileSearch)) + } + if (!loadSchema() || !openDictionaries(tuneFileSearch)) { return false; + } const Schema &oldSchema = old._schema; for (SchemaUtil::IndexIterator itr(_schema); itr.isValid(); ++itr) { vespalib::string fieldDir = _indexDir + "/" + itr.getName() + "/"; SchemaUtil::IndexSettings settings = itr.getIndexSettings(); - if (settings.hasError()) + if (settings.hasError()) { return false; + } bool hasPhraseOcc = settings.hasPhrases(); SchemaUtil::IndexIterator oItr(oldSchema, itr); - if (!itr.hasMatchingOldFields(oldSchema, hasPhraseOcc) || - !oItr.isValid()) { - if (!openField(fieldDir, tuneFileSearch)) + if (!itr.hasMatchingOldFields(oldSchema, hasPhraseOcc) || !oItr.isValid()) { + if (!openField(fieldDir, tuneFileSearch)) { return false; + } } else { uint32_t oldPacked = oItr.getIndex(); _postingFiles.push_back(old._postingFiles[oldPacked]); diff --git a/searchlib/src/vespa/searchlib/diskindex/docidmapper.cpp b/searchlib/src/vespa/searchlib/diskindex/docidmapper.cpp index 602b8143fd1..f8534ed62ff 100644 --- a/searchlib/src/vespa/searchlib/diskindex/docidmapper.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/docidmapper.cpp @@ -50,8 +50,9 @@ bool DocIdMapping::readDocIdLimit(const vespalib::string &mergedDir) { uint32_t docIdLimit = 0; - if (!search::docsummary::DocumentSummary::readDocIdLimit(mergedDir, docIdLimit)) + if (!search::docsummary::DocumentSummary::readDocIdLimit(mergedDir, docIdLimit)) { return false; + } _docIdLimit = docIdLimit; return true; } diff --git a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h index 169e06a64ca..08b4865cb0a 100644 --- a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h +++ b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h @@ -57,8 +57,7 @@ public: uint32_t mapDocId(uint32_t docId) const { assert(docId < _docIdLimit); - if (_selector != nullptr && - (docId >= _selectorLimit || _selector[docId] != _selectorId)) { + if (_selector != nullptr && (docId >= _selectorLimit || _selector[docId] != _selectorId)) { docId = noDocId(); } return docId; diff --git a/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp b/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp index 7b9a9b4bdd4..f6e4da945e0 100644 --- a/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp @@ -87,11 +87,12 @@ makePosOccWrite(const vespalib::string &name, name.c_str()); } } - if (dynamicK) + if (dynamicK) { posOccWrite = new ZcPosOccSeqWrite(schema, indexId, posOccCountWrite); - else + } else { posOccWrite = new Zc4PosOccSeqWrite(schema, indexId, posOccCountWrite); + } posOccWrite->setFeatureParams(featureParams); posOccWrite->setParams(params); @@ -132,10 +133,11 @@ makePosOccRead(const vespalib::string &name, name.c_str()); } } - if (dynamicK) + if (dynamicK) { posOccRead = new ZcPosOccSeqRead(posOccCountRead); - else + } else { posOccRead = new Zc4PosOccSeqRead(posOccCountRead); + } posOccRead->setFeatureParams(featureParams); return posOccRead; diff --git a/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp b/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp index a56771f179a..96b106a15da 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp @@ -81,8 +81,9 @@ FieldReader::read() } --_residue; readDocIdAndFeatures(); - if (_docIdAndFeatures._docId != NO_DOC) + if (_docIdAndFeatures._docId != NO_DOC) { return; + } } } @@ -198,10 +199,12 @@ FieldReader::allocFieldReader(const SchemaUtil::IndexIterator &index, const Schema &oldSchema) { assert(index.isValid()); - if (index.hasMatchingOldFields(oldSchema, false)) + if (index.hasMatchingOldFields(oldSchema, false)) { return std::make_unique<FieldReader>(); // The common case - if (!index.hasOldFields(oldSchema, false)) + } + if (!index.hasOldFields(oldSchema, false)) { return std::make_unique<FieldReaderEmpty>(index); // drop data + } // field exists in old schema with different collection type setting return std::make_unique<FieldReaderStripInfo>(index); // degraded } @@ -261,8 +264,9 @@ FieldReaderStripInfo::read() for (;;) { FieldReader::read(); DocIdAndFeatures &features = _docIdAndFeatures; - if (_wordNum == noWordNumHigh()) + if (_wordNum == noWordNumHigh()) { return; + } assert(!features.getRaw()); uint32_t numElements = features._elements.size(); assert(numElements > 0); @@ -270,15 +274,15 @@ FieldReaderStripInfo::read() features._elements.begin(); if (_hasElements) { if (!_hasElementWeights) { - for (uint32_t elementDone = 0; elementDone < numElements; - ++elementDone, ++element) { + for (uint32_t elementDone = 0; elementDone < numElements; ++elementDone, ++element) { element->setWeight(1); } assert(element == features._elements.end()); } } else { - if (element->getElementId() != 0) + if (element->getElementId() != 0) { continue; // Drop this entry, try to read new entry + } element->setWeight(1); features._wordPositions.resize(element->getNumOccs()); if (numElements > 1) { @@ -297,10 +301,11 @@ FieldReaderStripInfo::getFeatureParams(PostingListParams ¶ms) vespalib::string paramsPrefix = PosOccFieldParams::getParamsPrefix(0); vespalib::string collStr = paramsPrefix + ".collectionType"; if (_hasElements) { - if (_hasElementWeights) + if (_hasElementWeights) { params.setStr(collStr, "weightedSet"); - else + } else { params.setStr(collStr, "array"); + } } else params.setStr(collStr, "single"); params.erase("encoding"); diff --git a/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp b/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp index abc7d573db3..6454c0851a7 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp @@ -108,8 +108,9 @@ FieldWriter::flush() assert(_compactWordNum != 0); _dictFile->writeWord(_word, counts); // Write bitmap entries - if (_bvc.getCrossedBitVectorLimit()) + if (_bvc.getCrossedBitVectorLimit()) { _bmapfile.addWordSingle(_compactWordNum, _bvc.getBitVector()); + } _bvc.clear(); counts.clear(); } else { diff --git a/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp b/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp index 5861f50d738..ef3885a8e67 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fileheader.cpp @@ -33,8 +33,9 @@ FileHeader::taste(const vespalib::string &name, vespalib::FileHeader header; FastOS_File file; - if (tuneFileRead.getWantDirectIO()) + if (tuneFileRead.getWantDirectIO()) { file.EnableDirectIO(); + } bool res = file.OpenReadOnly(name.c_str()); if (!res) { return false; @@ -98,8 +99,9 @@ FileHeader::taste(const vespalib::string &name, vespalib::asciistream as; as << "format." << i; vespalib::stringref key(as.str()); - if (!header.hasTag(key)) + if (!header.hasTag(key)) { break; + } _formats.push_back(header.getTag(key).asString()); } return true; @@ -109,8 +111,9 @@ bool FileHeader::taste(const vespalib::string &name, const TuneFileSeqWrite &tuneFileWrite) { TuneFileSeqRead tuneFileRead; - if (tuneFileWrite.getWantDirectIO()) + if (tuneFileWrite.getWantDirectIO()) { tuneFileRead.setWantDirectIO(); + } return taste(name, tuneFileRead); } @@ -118,8 +121,9 @@ bool FileHeader::taste(const vespalib::string &name, const TuneFileRandRead &tuneFileSearch) { TuneFileSeqRead tuneFileRead; - if (tuneFileSearch.getWantDirectIO()) + if (tuneFileSearch.getWantDirectIO()) { tuneFileRead.setWantDirectIO(); + } return taste(name, tuneFileRead); } diff --git a/searchlib/src/vespa/searchlib/diskindex/fusion.cpp b/searchlib/src/vespa/searchlib/diskindex/fusion.cpp index 8e58853e826..2f45ef8e532 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fusion.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fusion.cpp @@ -133,10 +133,9 @@ Fusion::renumberFieldWordIds(const SchemaUtil::IndexIterator &index) PostingPriorityQueue<DictionaryWordReader> heap; WordAggregator out; - if (!openInputWordReaders(index, readers, heap)) + if (!openInputWordReaders(index, readers, heap)) { return false; - - + } heap.merge(out, 4); assert(heap.empty()); _numWordIds = out.getWordNum(); @@ -148,9 +147,9 @@ Fusion::renumberFieldWordIds(const SchemaUtil::IndexIterator &index) // Now read mapping files back into an array // XXX: avoid this, and instead make the array here - if (!ReadMappingFiles(&index)) + if (!ReadMappingFiles(&index)) { return false; - + } LOG(debug, "Finished renumbering words IDs for field %s", indexName.c_str()); @@ -165,8 +164,9 @@ Fusion::mergeFields() const Schema &schema = getSchema(); for (IndexIterator index(schema); index.isValid(); ++index) { - if (!mergeField(index.getIndex())) + if (!mergeField(index.getIndex())) { return false; + } } return true; } @@ -182,13 +182,14 @@ Fusion::mergeField(uint32_t id) IndexIterator index(schema, id); const vespalib::string &indexName = index.getName(); IndexSettings settings = index.getIndexSettings(); - if (settings.hasError()) + if (settings.hasError()) { return false; + } vespalib::string indexDir = _outDir + "/" + indexName; - if (FileKit::hasStamp(indexDir + "/.mergeocc_done")) + if (FileKit::hasStamp(indexDir + "/.mergeocc_done")) { return true; - + } vespalib::mkdir(indexDir.c_str(), false); LOG(debug, "mergeField for field %s dir %s", @@ -209,12 +210,14 @@ Fusion::mergeField(uint32_t id) indexName.c_str(), indexDir.c_str()); LOG_ABORT("should not be reached"); } - if (!FileKit::createStamp(indexDir + "/.mergeocc_done")) + if (!FileKit::createStamp(indexDir + "/.mergeocc_done")) { return false; + } vespalib::File::sync(indexDir); - if (!CleanTmpDirs()) + if (!CleanTmpDirs()) { return false; + } LOG(debug, "Finished mergeField for field %s dir %s", indexName.c_str(), indexDir.c_str()); @@ -233,26 +236,32 @@ Fusion::selectCookedOrRawFeatures(Reader &reader, Writer &writer) vespalib::string cookedFormat; vespalib::string rawFormat; - if (!reader.isValid()) + if (!reader.isValid()) { return true; + } { writer.getFeatureParams(featureParams); cookedFormat = featureParams.getStr("cookedEncoding"); rawFormat = featureParams.getStr("encoding"); - if (rawFormat == "") + if (rawFormat == "") { rawFormatOK = false; // Typically uncompressed file + } outFeatureParams = featureParams; } { reader.getFeatureParams(featureParams); - if (cookedFormat != featureParams.getStr("cookedEncoding")) + if (cookedFormat != featureParams.getStr("cookedEncoding")) { cookedFormatOK = false; - if (rawFormat != featureParams.getStr("encoding")) + } + if (rawFormat != featureParams.getStr("encoding")) { rawFormatOK = false; - if (featureParams != outFeatureParams) + } + if (featureParams != outFeatureParams) { rawFormatOK = false; - if (!reader.allowRawFeatures()) + } + if (!reader.allowRawFeatures()) { rawFormatOK = false; // Reader transforms data + } } if (!cookedFormatOK) { LOG(error, @@ -265,8 +274,9 @@ Fusion::selectCookedOrRawFeatures(Reader &reader, Writer &writer) reader.setFeatureParams(featureParams); reader.getFeatureParams(featureParams); if (featureParams.isSet("cookedEncoding") || - rawFormat != featureParams.getStr("encoding")) + rawFormat != featureParams.getStr("encoding")) { rawFormatOK = false; + } if (!rawFormatOK) { LOG(error, "Cannot perform fusion, raw format setting failed"); return false; @@ -292,10 +302,9 @@ Fusion::openInputFieldReaders(const SchemaUtil::IndexIterator &index, auto reader = FieldReader::allocFieldReader(index, oldSchema); reader->setup(oi.getWordNumMapping(), oi.getDocIdMapping()); - if (!reader->open(oi.getPath() + "/" + - indexName + "/", - _tuneFileIndexing._read)) + if (!reader->open(oi.getPath() + "/" + indexName + "/", _tuneFileIndexing._read)) { return false; + } readers.push_back(std::move(reader)); } return true; @@ -332,12 +341,15 @@ Fusion::setupMergeHeap(const std::vector<std::unique_ptr<FieldReader> > & PostingPriorityQueue<FieldReader> &heap) { for (auto &reader : readers) { - if (!selectCookedOrRawFeatures(*reader, writer)) + if (!selectCookedOrRawFeatures(*reader, writer)) { return false; - if (reader->isValid()) + } + if (reader->isValid()) { reader->read(); - if (reader->isValid()) + } + if (reader->isValid()) { heap.initialAdd(reader.get()); + } } return true; } @@ -352,19 +364,23 @@ Fusion::mergeFieldPostings(const SchemaUtil::IndexIterator &index) FieldWriter fieldWriter(_docIdLimit, _numWordIds); vespalib::string indexName = index.getName(); - if (!openInputFieldReaders(index, readers)) + if (!openInputFieldReaders(index, readers)) { return false; - if (!openFieldWriter(index, fieldWriter)) + } + if (!openFieldWriter(index, fieldWriter)) { return false; - if (!setupMergeHeap(readers, fieldWriter, heap)) + } + if (!setupMergeHeap(readers, fieldWriter, heap)) { return false; + } heap.merge(fieldWriter, 4); assert(heap.empty()); for (auto &reader : readers) { - if (!reader->close()) + if (!reader->close()) { return false; + } } if (!fieldWriter.close()) { LOG(error, "Could not close output posocc + dictionary in %s/%s", @@ -389,8 +405,9 @@ Fusion::ReadMappingFiles(const SchemaUtil::IndexIterator *index) const Schema &oldSchema = oi.getSchema(); if (!SchemaUtil::getIndexIds(oldSchema, DataType::STRING, - oldIndexes)) + oldIndexes)) { return false; + } if (oldIndexes.empty()) { wordNumMapping.noMappingFile(); continue; @@ -444,8 +461,9 @@ Fusion::CleanTmpDirs() const vespalib::string &tmpindexpath = tmpindexpath0.str(); FastOS_StatInfo statInfo; if (!FastOS_File::Stat(tmpindexpath.c_str(), &statInfo)) { - if (statInfo._error == FastOS_StatInfo::FileNotFound) + if (statInfo._error == FastOS_StatInfo::FileNotFound) { break; + } LOG(error, "Failed to stat tmpdir %s", tmpindexpath.c_str()); return false; } @@ -486,17 +504,20 @@ Fusion::readSchemaFiles() OldIndex &oi = **oldIndexIt; vespalib::string oldcfname = oi.getPath() + "/schema.txt"; Schema::SP schema(new Schema); - if (!schema->loadFromFile(oldcfname)) + if (!schema->loadFromFile(oldcfname)) { return false; - if (!SchemaUtil::validateSchema(*_schema)) + } + if (!SchemaUtil::validateSchema(*_schema)) { return false; + } oi.setSchema(schema); } /* TODO: Check compatibility */ bool res = checkSchemaCompat(); - if (!res) + if (!res) { LOG(error, "Index fusion cannot continue due to incompatible indexes"); + } return res; } @@ -516,9 +537,9 @@ Fusion::merge(const Schema &schema, // Limit docIdLimit in output based on selections that cannot be satisfied uint32_t sourcesSize = sources.size(); - while (trimmedDocIdLimit > 0 && - selector[trimmedDocIdLimit - 1] >= sourcesSize) + while (trimmedDocIdLimit > 0 && selector[trimmedDocIdLimit - 1] >= sourcesSize) { --trimmedDocIdLimit; + } FastOS_StatInfo statInfo; if (!FastOS_File::Stat(dir.c_str(), &statInfo)) { @@ -577,8 +598,9 @@ Fusion::merge(const Schema &schema, idx); } fusion->setDocIdLimit(trimmedDocIdLimit); - if (!fusion->mergeFields()) + if (!fusion->mergeFields()) { return false; + } return true; } diff --git a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp index 91b7a813755..a3c37cb91f6 100644 --- a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp @@ -249,8 +249,9 @@ public: bool operator<(const SingleIterator &rhs) const { - if (_docId != rhs._docId) + if (_docId != rhs._docId) { return _docId < rhs._docId; + } return _localFieldId < rhs._localFieldId; } }; @@ -505,8 +506,9 @@ SingleIterator::appendFeatures(DocIdAndFeatures &features) } } ++_dFeatures; - if (_dFeatures != _dFeaturesE) + if (_dFeatures != _dFeaturesE) { _docId = _dFeatures->getDocId(); + } } @@ -529,8 +531,9 @@ IndexBuilder::IndexBuilder(const Schema &schema) const Schema::IndexField &iField = schema.getIndexField(i); FieldHandle fh(schema, i, this); // Only know how to handle string index for now. - if (iField.getDataType() == DataType::STRING) + if (iField.getDataType() == DataType::STRING) { fh.setValid(); + } _fields.push_back(fh); } } @@ -643,8 +646,9 @@ IndexBuilder::setPrefix(vespalib::stringref prefix) vespalib::string IndexBuilder::appendToPrefix(vespalib::stringref name) { - if (_prefix.empty()) + if (_prefix.empty()) { return name; + } return _prefix + "/" + name; } @@ -663,8 +667,9 @@ IndexBuilder::open(uint32_t docIdLimit, uint64_t numWordIds, } // TODO: Filter for text indexes for (FieldHandle & fh : _fields) { - if (!fh.getValid()) + if (!fh.getValid()) { continue; + } vespalib::mkdir(fh.getDir(), false); fh.open(docIdLimit, numWordIds, tuneFileIndexing._write, fileHeaderContext); diff --git a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp index bc911e230bc..7be1eccecb5 100644 --- a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp @@ -19,8 +19,9 @@ WordNumMapping::readMappingFile(const vespalib::string &name, { // Open word mapping file Fast_BufferedFile old2newwordfile(new FastOS_File); - if (tuneFileRead.getWantDirectIO()) + if (tuneFileRead.getWantDirectIO()) { old2newwordfile.EnableDirectIO(); + } // XXX no checking for success old2newwordfile.ReadOpen(name.c_str()); int64_t tempfilesize = old2newwordfile.GetSize(); diff --git a/searchlib/src/vespa/searchlib/diskindex/zcbuf.cpp b/searchlib/src/vespa/searchlib/diskindex/zcbuf.cpp index f5c1ee19af9..1f5ce4260a9 100644 --- a/searchlib/src/vespa/searchlib/diskindex/zcbuf.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/zcbuf.cpp @@ -24,10 +24,12 @@ ZcBuf::clearReserve(size_t reserveSize) { if (reserveSize + zcSlack() > _mallocSize) { size_t newSize = _mallocSize * 2; - if (newSize < 16) + if (newSize < 16) { newSize = 16; - while (newSize < reserveSize + zcSlack()) + } + while (newSize < reserveSize + zcSlack()) { newSize *= 2; + } uint8_t *newBuf = static_cast<uint8_t *>(malloc(newSize)); free(_mallocStart); _mallocStart = newBuf; @@ -43,13 +45,15 @@ ZcBuf::expand() { size_t newSize = _mallocSize * 2; size_t oldSize = size(); - if (newSize < 16) + if (newSize < 16) { newSize = 16; + } uint8_t *newBuf = static_cast<uint8_t *>(malloc(newSize)); - if (oldSize > 0) + if (oldSize > 0) { memcpy(newBuf, _mallocStart, oldSize); + } free(_mallocStart); _mallocStart = newBuf; _mallocSize = newSize; diff --git a/searchlib/src/vespa/searchlib/diskindex/zcbuf.h b/searchlib/src/vespa/searchlib/diskindex/zcbuf.h index c7caeb09733..b81cc2a9720 100644 --- a/searchlib/src/vespa/searchlib/diskindex/zcbuf.h +++ b/searchlib/src/vespa/searchlib/diskindex/zcbuf.h @@ -31,8 +31,9 @@ public: void expand(); void maybeExpand() { - if (__builtin_expect(_valI >= _valE, false)) + if (__builtin_expect(_valI >= _valE, false)) { expand(); + } } void encode(uint32_t num) { diff --git a/searchlib/src/vespa/searchlib/diskindex/zcposoccrandread.cpp b/searchlib/src/vespa/searchlib/diskindex/zcposoccrandread.cpp index b8d5ee89276..90680851859 100644 --- a/searchlib/src/vespa/searchlib/diskindex/zcposoccrandread.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/zcposoccrandread.cpp @@ -48,8 +48,9 @@ ZcPosOccRandRead::ZcPosOccRandRead() ZcPosOccRandRead::~ZcPosOccRandRead() { - if (_file->IsOpened()) + if (_file->IsOpened()) { close(); + } } @@ -68,8 +69,9 @@ createIterator(const PostingListCounts &counts, assert((counts._numDocs != 0) == (counts._bitLength != 0)); assert(handle._bitOffsetMem <= handle._bitOffset); - if (handle._bitLength == 0) + if (handle._bitLength == 0) { return new search::queryeval::EmptySearch; + } const char *cmem = static_cast<const char *>(handle._mem); uint64_t memOffset = reinterpret_cast<unsigned long>(cmem) & 7; @@ -112,8 +114,9 @@ ZcPosOccRandRead::readPostingList(const PostingListCounts &counts, (void) counts; handle.drop(); - if (handle._bitLength == 0) + if (handle._bitLength == 0) { return; + } uint64_t startOffset = (handle._bitOffset + _headerBitSize) >> 3; // Align start at 64-bit boundary @@ -136,8 +139,9 @@ ZcPosOccRandRead::readPostingList(const PostingListCounts &counts, size_t padExtraAfter; // Decode prefetch space _file->DirectIOPadding(startOffset, vectorLen, padBefore, padAfter); padExtraAfter = 0; - if (padAfter < 16) + if (padAfter < 16) { padExtraAfter = 16 - padAfter; + } size_t mallocLen = padBefore + vectorLen + padAfter + padExtraAfter; void *mallocStart = nullptr; @@ -275,8 +279,9 @@ createIterator(const PostingListCounts &counts, assert((counts._numDocs != 0) == (counts._bitLength != 0)); assert(handle._bitOffsetMem <= handle._bitOffset); - if (handle._bitLength == 0) + if (handle._bitLength == 0) { return new search::queryeval::EmptySearch; + } const char *cmem = static_cast<const char *>(handle._mem); uint64_t memOffset = reinterpret_cast<unsigned long>(cmem) & 7; diff --git a/searchlib/src/vespa/searchlib/diskindex/zcposting.cpp b/searchlib/src/vespa/searchlib/diskindex/zcposting.cpp index 01e2a597cca..19faceb2b27 100644 --- a/searchlib/src/vespa/searchlib/diskindex/zcposting.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/zcposting.cpp @@ -96,8 +96,9 @@ void Zc4PostingSeqRead:: readCommonWordDocIdAndFeatures(DocIdAndFeatures &features) { - if (_zcDocIds._valI >= _zcDocIds._valE && _hasMore) + if (_zcDocIds._valI >= _zcDocIds._valE && _hasMore) { readWordStart(); // Read start of next chunk + } // Split docid & features. assert(_zcDocIds._valI < _zcDocIds._valE); uint32_t docIdPos = _zcDocIds.pos(); @@ -191,8 +192,9 @@ readDocIdAndFeatures(DocIdAndFeatures &features) DecodeContext &d = *_decodeContext; uint64_t curOffset = d.getReadOffset(); assert(curOffset <= _rangeEndOffset); - if (curOffset < _rangeEndOffset) + if (curOffset < _rangeEndOffset) { readWordStart(); + } } if (_residue == 0) { // Don't read past end of posting list. @@ -200,8 +202,9 @@ readDocIdAndFeatures(DocIdAndFeatures &features) return; } } - if (_lastDocId > 0) + if (_lastDocId > 0) { return readCommonWordDocIdAndFeatures(features); + } // Interleaves docid & features typedef FeatureEncodeContextBE EC; DecodeContext &d = *_decodeContext; @@ -234,10 +237,11 @@ Zc4PostingSeqRead::readWordStartWithSkip() uint64_t val64; const uint64_t *valE = d._valE; - if (_hasMore) + if (_hasMore) { ++_chunkNo; - else + } else { _chunkNo = 0; + } assert(_numDocs >= _minSkipDocs || _hasMore); bool hasMore = false; if (__builtin_expect(_numDocs >= _minChunkDocs, false)) { @@ -246,9 +250,10 @@ Zc4PostingSeqRead::readWordStartWithSkip() length = 1; UC64BE_READBITS_NS(o, EC); } - if (_dynamicK) + if (_dynamicK) { _docIdK = EC::calcDocIdK((_hasMore || hasMore) ? 1 : _numDocs, _docIdLimit); + } if (_hasMore || hasMore) { if (_rangeEndOffset == 0) { assert(hasMore == (_chunkNo + 1 < _counts._segments.size())); @@ -360,35 +365,43 @@ Zc4PostingSeqRead::readWordStartWithSkip() _l4Skip.clearReserve(l4SkipSize); _decodeContext->readBytes(_zcDocIds._valI, docIdsSize); _zcDocIds._valE = _zcDocIds._valI + docIdsSize; - if (l1SkipSize > 0) + if (l1SkipSize > 0) { _decodeContext->readBytes(_l1Skip._valI, l1SkipSize); + } _l1Skip._valE = _l1Skip._valI + l1SkipSize; - if (l2SkipSize > 0) + if (l2SkipSize > 0) { _decodeContext->readBytes(_l2Skip._valI, l2SkipSize); + } _l2Skip._valE = _l2Skip._valI + l2SkipSize; - if (l3SkipSize > 0) + if (l3SkipSize > 0) { _decodeContext->readBytes(_l3Skip._valI, l3SkipSize); + } _l3Skip._valE = _l3Skip._valI + l3SkipSize; - if (l4SkipSize > 0) + if (l4SkipSize > 0) { _decodeContext->readBytes(_l4Skip._valI, l4SkipSize); + } _l4Skip._valE = _l4Skip._valI + l4SkipSize; - if (l1SkipSize > 0) + if (l1SkipSize > 0) { _l1SkipDocId = _l1Skip.decode() + 1 + _prevDocId; - else + } else { _l1SkipDocId = _lastDocId; - if (l2SkipSize > 0) + } + if (l2SkipSize > 0) { _l2SkipDocId = _l2Skip.decode() + 1 + _prevDocId; - else + } else { _l2SkipDocId = _lastDocId; - if (l3SkipSize > 0) + } + if (l3SkipSize > 0) { _l3SkipDocId = _l3Skip.decode() + 1 + _prevDocId; - else + } else { _l3SkipDocId = _lastDocId; - if (l4SkipSize > 0) + } + if (l4SkipSize > 0) { _l4SkipDocId = _l4Skip.decode() + 1 + _prevDocId; - else + } else { _l4SkipDocId = _lastDocId; + } _l1SkipDocIdPos = 0; _l1SkipFeaturesPos = _decodeContext->getReadOffset(); _l2SkipDocIdPos = 0; @@ -421,8 +434,9 @@ Zc4PostingSeqRead::readWordStart() K_VALUE_ZCPOSTING_NUMDOCS, EC); UC64_DECODECONTEXT_STORE(o, _decodeContext->_); - if (oCompr >= valE) + if (oCompr >= valE) { _readContext.readComprBuffer(); + } _numDocs = static_cast<uint32_t>(val64) + 1; _residue = _numDocs; _prevDocId = _hasMore ? _lastDocId : 0u; @@ -437,8 +451,9 @@ Zc4PostingSeqRead::readWordStart() readWordStartWithSkip(); // Decode context is not positioned at start of features } else { - if (_dynamicK) + if (_dynamicK) { _docIdK = EC::calcDocIdK(_numDocs, _docIdLimit); + } _lastDocId = 0u; // Decode context is not positioned at start of docids & features } @@ -464,8 +479,9 @@ bool Zc4PostingSeqRead::open(const vespalib::string &name, const TuneFileSeqRead &tuneFileRead) { - if (tuneFileRead.getWantDirectIO()) + if (tuneFileRead.getWantDirectIO()) { _file.EnableDirectIO(); + } bool res = _file.OpenReadOnly(name.c_str()); if (res) { _readContext.setFile(&_file); @@ -747,8 +763,9 @@ void Zc4PostingSeqWrite:: setParams(const PostingListParams ¶ms) { - if (_countFile != nullptr) + if (_countFile != nullptr) { _countFile->setParams(params); + } _writer.set_posting_list_params(params); } @@ -808,8 +825,9 @@ readDocIdAndFeatures(DocIdAndFeatures &features) DecodeContext &d = *_decodeContext; uint64_t curOffset = d.getReadOffset(); assert(curOffset <= _rangeEndOffset); - if (curOffset < _rangeEndOffset) + if (curOffset < _rangeEndOffset) { readWordStart(); + } } if (_residue == 0) { // Don't read past end of posting list. diff --git a/searchlib/src/vespa/searchlib/diskindex/zcpostingiterators.cpp b/searchlib/src/vespa/searchlib/diskindex/zcpostingiterators.cpp index 513f39c47f8..95679bb0af2 100644 --- a/searchlib/src/vespa/searchlib/diskindex/zcpostingiterators.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/zcpostingiterators.cpp @@ -57,8 +57,9 @@ Zc4RareWordPostingIterator<bigEndian>::doSeek(uint32_t docId) UC64_DECODECONTEXT_CONSTRUCTOR(o, _decodeContext->_); if (getUnpacked()) { clearUnpacked(); - if (__builtin_expect(--_residue == 0, false)) + if (__builtin_expect(--_residue == 0, false)) { goto atbreak; + } UC64_DECODEEXPGOLOMB_NS(o, K_VALUE_ZCPOSTING_DELTA_DOCID, EC); oDocId += 1 + static_cast<uint32_t>(val64); #if DEBUG_ZCPOSTING_PRINTF @@ -70,8 +71,9 @@ Zc4RareWordPostingIterator<bigEndian>::doSeek(uint32_t docId) UC64_DECODECONTEXT_STORE(o, _decodeContext->_); _decodeContext->skipFeatures(1); UC64_DECODECONTEXT_LOAD(o, _decodeContext->_); - if (__builtin_expect(--_residue == 0, false)) + if (__builtin_expect(--_residue == 0, false)) { goto atbreak; + } UC64_DECODEEXPGOLOMB_NS(o, K_VALUE_ZCPOSTING_DELTA_DOCID, EC); oDocId += 1 + static_cast<uint32_t>(val64); #if DEBUG_ZCPOSTING_PRINTF @@ -92,8 +94,9 @@ template <bool bigEndian> void Zc4RareWordPostingIterator<bigEndian>::doUnpack(uint32_t docId) { - if (!_matchData.valid() || getUnpacked()) + if (!_matchData.valid() || getUnpacked()) { return; + } assert(docId == getDocId()); _decodeContext->unpackFeatures(_matchData, docId); setUnpacked(); @@ -150,8 +153,9 @@ ZcRareWordPostingIterator<bigEndian>::doSeek(uint32_t docId) UC64_DECODECONTEXT_CONSTRUCTOR(o, _decodeContext->_); if (getUnpacked()) { clearUnpacked(); - if (__builtin_expect(--_residue == 0, false)) + if (__builtin_expect(--_residue == 0, false)) { goto atbreak; + } UC64_DECODEEXPGOLOMB_NS(o, _docIdK, EC); oDocId += 1 + static_cast<uint32_t>(val64); #if DEBUG_ZCPOSTING_PRINTF @@ -163,8 +167,9 @@ ZcRareWordPostingIterator<bigEndian>::doSeek(uint32_t docId) UC64_DECODECONTEXT_STORE(o, _decodeContext->_); _decodeContext->skipFeatures(1); UC64_DECODECONTEXT_LOAD(o, _decodeContext->_); - if (__builtin_expect(--_residue == 0, false)) + if (__builtin_expect(--_residue == 0, false)) { goto atbreak; + } UC64_DECODEEXPGOLOMB_NS(o, _docIdK, EC); oDocId += 1 + static_cast<uint32_t>(val64); #if DEBUG_ZCPOSTING_PRINTF @@ -264,8 +269,9 @@ ZcPostingIterator<bigEndian>::readWordStart(uint32_t docIdLimit) } UC64_READBITS_NS(o, EC); } - if (_dynamicK) + if (_dynamicK) { _docIdK = EC::calcDocIdK((_hasMore || hasMore) ? 1 : _numDocs, docIdLimit); + } UC64_DECODEEXPGOLOMB_NS(o, K_VALUE_ZCPOSTING_DOCIDSSIZE, EC); uint32_t docIdsSize = val64 + 1; UC64_DECODEEXPGOLOMB_NS(o, K_VALUE_ZCPOSTING_L1SKIPSIZE, EC); @@ -357,8 +363,9 @@ ZcPostingIteratorBase::doL4SkipSeek(uint32_t docId) if (__builtin_expect(docId > _chunk._lastDocId, false)) { doChunkSkipSeek(docId); - if (docId <= _l4._skipDocId) + if (docId <= _l4._skipDocId) { return; + } } do { lastL4SkipDocId = _l4._skipDocId; @@ -409,8 +416,9 @@ ZcPostingIteratorBase::doL3SkipSeek(uint32_t docId) if (__builtin_expect(docId > _l4._skipDocId, false)) { doL4SkipSeek(docId); - if (docId <= _l3._skipDocId) + if (docId <= _l3._skipDocId) { return; + } } do { lastL3SkipDocId = _l3._skipDocId; @@ -455,8 +463,9 @@ ZcPostingIteratorBase::doL2SkipSeek(uint32_t docId) if (__builtin_expect(docId > _l3._skipDocId, false)) { doL3SkipSeek(docId); - if (docId <= _l2._skipDocId) + if (docId <= _l2._skipDocId) { return; + } } do { lastL2SkipDocId = _l2._skipDocId; @@ -494,8 +503,9 @@ ZcPostingIteratorBase::doL1SkipSeek(uint32_t docId) uint32_t lastL1SkipDocId; if (__builtin_expect(docId > _l2._skipDocId, false)) { doL2SkipSeek(docId); - if (docId <= _l1._skipDocId) + if (docId <= _l1._skipDocId) { return; + } } do { lastL1SkipDocId = _l1._skipDocId; @@ -564,8 +574,9 @@ template <bool bigEndian> void ZcPostingIterator<bigEndian>::doUnpack(uint32_t docId) { - if (!_matchData.valid() || getUnpacked()) + if (!_matchData.valid() || getUnpacked()) { return; + } if (_featureSeekPos != 0) { // Handle deferred feature position seek now. featureSeek(_featureSeekPos); @@ -573,8 +584,9 @@ ZcPostingIterator<bigEndian>::doUnpack(uint32_t docId) } assert(docId == getDocId()); uint32_t needUnpack = getNeedUnpack(); - if (needUnpack > 1) + if (needUnpack > 1) { _decodeContext->skipFeatures(needUnpack - 1); + } _decodeContext->unpackFeatures(_matchData, docId); setUnpacked(); } diff --git a/searchlib/src/vespa/searchlib/index/docbuilder.cpp b/searchlib/src/vespa/searchlib/index/docbuilder.cpp index f3d76fc815d..b79aa423413 100644 --- a/searchlib/src/vespa/searchlib/index/docbuilder.cpp +++ b/searchlib/src/vespa/searchlib/index/docbuilder.cpp @@ -224,12 +224,14 @@ DocBuilder::IndexFieldHandle::IndexFieldHandle(const FixedTypeRepo & repo, const _str.reserve(1023); if (_sfield.getCollectionType() == CollectionType::SINGLE) { - if (*_value->getDataType() == document::UrlDataType::getInstance()) + if (*_value->getDataType() == document::UrlDataType::getInstance()) { _uriField = true; + } } else { const CollectionFieldValue * value = dynamic_cast<CollectionFieldValue *>(_value.get()); - if (value->getNestedType() == document::UrlDataType::getInstance()) + if (value->getNestedType() == document::UrlDataType::getInstance()) { _uriField = true; + } } startAnnotate(); } @@ -245,10 +247,12 @@ void DocBuilder::IndexFieldHandle::addStr(const vespalib::string &val) { assert(_spanTree); - if (val.empty()) + if (val.empty()) { return; - if (!_skipAutoSpace && _autoSpace) + } + if (!_skipAutoSpace && _autoSpace) { addSpace(); + } _skipAutoSpace = false; _spanStart = _strSymbols; append(val); @@ -273,15 +277,16 @@ void DocBuilder::IndexFieldHandle::addNoWordStr(const vespalib::string &val) { assert(_spanTree); - if (val.empty()) + if (val.empty()) { return; + } _spanStart = _strSymbols; append(val); if (_autoAnnotate) { addSpan(); - if (val[0] == ' ' || val[0] == '\t') + if (val[0] == ' ' || val[0] == '\t') { addSpaceTokenAnnotation(); - else if (val[0] >= '0' && val[0] <= '9') { + } else if (val[0] >= '0' && val[0] <= '9') { addNumericTokenAnnotation(); } else { addAlphabeticTokenAnnotation(); @@ -309,10 +314,11 @@ DocBuilder::IndexFieldHandle::addTokenizedString(const vespalib::string &val, (urlMode && (c == '-' || c == '_')); if (oldWord != newWord) { if (!sbuf.empty()) { - if (oldWord) + if (oldWord) { addStr(sbuf); - else + } else { addNoWordStr(sbuf); + } sbuf.clear(); } oldWord = newWord; @@ -320,10 +326,11 @@ DocBuilder::IndexFieldHandle::addTokenizedString(const vespalib::string &val, w.putChar(c); } if (!sbuf.empty()) { - if (oldWord) + if (oldWord) { addStr(sbuf); - else + } else { addNoWordStr(sbuf); + } } } @@ -390,8 +397,9 @@ DocBuilder::IndexFieldHandle::onEndElement() { // Flush data for index field. assert(_subField.empty()); - if (_uriField) + if (_uriField) { return; + } StringFieldValue * value; if (_sfield.getCollectionType() != CollectionType::SINGLE) { value = dynamic_cast<StringFieldValue *>(_element.get()); @@ -419,8 +427,9 @@ DocBuilder::IndexFieldHandle::onEndElement() void DocBuilder::IndexFieldHandle::onEndField() { - if (_sfield.getCollectionType() == CollectionType::SINGLE) + if (_sfield.getCollectionType() == CollectionType::SINGLE) { onEndElement(); + } } void diff --git a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp index 2bc81947e70..a7ad475d6aa 100644 --- a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp +++ b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp @@ -139,9 +139,9 @@ document::DocumenttypesConfig DocTypeBuilder::makeConfig() const { for (uint32_t i = 0; i < _schema.getNumAttributeFields(); ++i) { const Schema::AttributeField &field = _schema.getAttributeField(i); UsedFields::const_iterator usf = usedFields.find(field.getName()); - if (usf != usedFields.end()) + if (usf != usedFields.end()) { continue; // taken as index field - + } const DataType *primitiveType = convert(field.getDataType()); if (primitiveType->getId() == DataType::T_TENSOR) { header_struct.addTensorField(field.getName(), dynamic_cast<const TensorDataType &>(*primitiveType).getTensorType().to_spec()); @@ -155,8 +155,9 @@ document::DocumenttypesConfig DocTypeBuilder::makeConfig() const { for (uint32_t i = 0; i < _schema.getNumSummaryFields(); ++i) { const Schema::SummaryField &field = _schema.getSummaryField(i); UsedFields::const_iterator usf = usedFields.find(field.getName()); - if (usf != usedFields.end()) + if (usf != usedFields.end()) { continue; // taken as index field or attribute field + } const DataType *primitiveType(convert(field.getDataType())); if (primitiveType->getId() == DataType::T_TENSOR) { header_struct.addTensorField(field.getName(), dynamic_cast<const TensorDataType &>(*primitiveType).getTensorType().to_spec()); diff --git a/searchlib/src/vespa/searchlib/index/postinglistfile.cpp b/searchlib/src/vespa/searchlib/index/postinglistfile.cpp index 3dda52a9871..0f0860f9145 100644 --- a/searchlib/src/vespa/searchlib/index/postinglistfile.cpp +++ b/searchlib/src/vespa/searchlib/index/postinglistfile.cpp @@ -97,8 +97,9 @@ PostingListFileRandReadPassThrough(PostingListFileRandRead *lower, PostingListFileRandReadPassThrough::~PostingListFileRandReadPassThrough() { - if (_ownLower) + if (_ownLower) { delete _lower; + } } search::queryeval::SearchIterator * diff --git a/searchlib/src/vespa/searchlib/index/postinglistparams.cpp b/searchlib/src/vespa/searchlib/index/postinglistparams.cpp index 1fb96206ba6..570bd997db3 100644 --- a/searchlib/src/vespa/searchlib/index/postinglistparams.cpp +++ b/searchlib/src/vespa/searchlib/index/postinglistparams.cpp @@ -17,8 +17,9 @@ PostingListParams::isSet(const vespalib::string &key) const Map::const_iterator it; it = _map.find(key); - if (it != _map.end()) + if (it != _map.end()) { return true; + } return false; } @@ -35,8 +36,9 @@ PostingListParams::getStr(const vespalib::string &key) const Map::const_iterator it; it = _map.find(key); - if (it != _map.end()) + if (it != _map.end()) { return it->second; + } return empty; } diff --git a/searchlib/src/vespa/searchlib/index/schema_index_fields.cpp b/searchlib/src/vespa/searchlib/index/schema_index_fields.cpp index 7b4c0ad47bf..b65575ab192 100644 --- a/searchlib/src/vespa/searchlib/index/schema_index_fields.cpp +++ b/searchlib/src/vespa/searchlib/index/schema_index_fields.cpp @@ -33,8 +33,7 @@ SchemaIndexFields::setup(const Schema &schema) if (uriField.valid(schema, field.getCollectionType())) { _uriFields.push_back(uriField); uriField.markUsed(usedFields); - } else if (uriField.broken(schema, - field.getCollectionType())) { + } else if (uriField.broken(schema, field.getCollectionType())) { // Broken removal of unused URI fields. uriField.markUsed(usedFields); } diff --git a/searchlib/src/vespa/searchlib/index/schemautil.cpp b/searchlib/src/vespa/searchlib/index/schemautil.cpp index 622779a1269..62f6cd08510 100644 --- a/searchlib/src/vespa/searchlib/index/schemautil.cpp +++ b/searchlib/src/vespa/searchlib/index/schemautil.cpp @@ -26,18 +26,21 @@ SchemaUtil::getIndexSettings(const Schema &schema, bool someNotPositions = false; const Schema::IndexField &iField = schema.getIndexField(index); - if (iField.hasPhrases()) + if (iField.hasPhrases()) { somePhrases = true; - else + } else { someNotPhrases = true; - if (iField.hasPrefix()) + } + if (iField.hasPrefix()) { somePrefixes = true; - else + } else { someNotPrefixes = true; - if (iField.hasPositions()) + } + if (iField.hasPositions()) { somePositions = true; - else + } else { someNotPositions = true; + } indexDataType = iField.getDataType(); if (indexDataType != DataType::STRING) { error = true; @@ -59,14 +62,17 @@ SchemaUtil::IndexIterator::hasOldFields(const Schema &oldSchema, getSchema().getIndexField(getIndex()); const vespalib::string &fieldName = newField.getName(); uint32_t oldFieldId = oldSchema.getIndexFieldId(fieldName); - if (oldFieldId == Schema::UNKNOWN_FIELD_ID) + if (oldFieldId == Schema::UNKNOWN_FIELD_ID) { return false; + } const Schema::IndexField &oldField = oldSchema.getIndexField(oldFieldId); - if (oldField.getDataType() != newField.getDataType()) + if (oldField.getDataType() != newField.getDataType()) { return false; // wrong data type - if (!phrases) + } + if (!phrases) { return true; + } return oldField.hasPhrases(); } @@ -79,13 +85,15 @@ SchemaUtil::IndexIterator::hasMatchingOldFields(const Schema &oldSchema, getSchema().getIndexField(getIndex()); const vespalib::string &fieldName = newField.getName(); uint32_t oldFieldId = oldSchema.getIndexFieldId(fieldName); - if (oldFieldId == Schema::UNKNOWN_FIELD_ID) + if (oldFieldId == Schema::UNKNOWN_FIELD_ID) { return false; + } if (phrases) { IndexIterator oldIterator(oldSchema, oldFieldId); IndexSettings settings = oldIterator.getIndexSettings(); - if (!settings.hasPhrases()) + if (!settings.hasPhrases()) { return false; + } } const Schema::IndexField &oldField = oldSchema.getIndexField(oldFieldId); @@ -139,8 +147,9 @@ SchemaUtil::addIndexField(Schema &schema, const Schema::IndexField &field) { bool ok = true; - if (!validateIndexField(field)) + if (!validateIndexField(field)) { ok = false; + } uint32_t fieldId = schema.getIndexFieldId(field.getName()); if (fieldId != Schema::UNKNOWN_FIELD_ID) { LOG(error, @@ -148,8 +157,9 @@ SchemaUtil::addIndexField(Schema &schema, field.getName().c_str()); ok = false; } - if (ok) + if (ok) { schema.addIndexField(field); + } return ok; } @@ -160,8 +170,9 @@ SchemaUtil::validateSchema(const Schema &schema) for (IndexIterator it(schema); it.isValid(); ++it) { uint32_t fieldId = it.getIndex(); const Schema::IndexField &field = schema.getIndexField(fieldId); - if (!validateIndexField(field)) + if (!validateIndexField(field)) { ok = false; + } if (schema.getIndexFieldId(field.getName()) != fieldId) { LOG(error, "Duplcate field %s", @@ -189,10 +200,12 @@ SchemaUtil::getIndexIds(const Schema &schema, indexes.clear(); for (IndexIterator i(schema); i.isValid(); ++i) { SchemaUtil::IndexSettings settings = i.getIndexSettings(); - if (settings.hasError()) + if (settings.hasError()) { return false; - if (settings.getDataType() == dataType) + } + if (settings.getDataType() == dataType) { indexes.push_back(i.getIndex()); + } } return true; } |