void findDiffMatches(const File* file, const License* license, size_t textStartPosition, size_t searchStartPosition, GArray* matches, unsigned int maxAllowedDiff, unsigned int minAdjacentMatches) { if (!matchNTokens(file->tokens, textStartPosition, file->tokens->len, license->tokens, searchStartPosition, license->tokens->len, minAdjacentMatches)) { return; } DiffResult* diffResult = findMatchAsDiffs(file->tokens, license->tokens, textStartPosition, searchStartPosition, maxAllowedDiff, minAdjacentMatches); if (diffResult) { Match* newMatch = diffResult2Match(diffResult, license); if (match_rank(newMatch) > MIN_ALLOWED_RANK) g_array_append_val(matches, newMatch); else { match_free(newMatch); } } }
inline DiffMatchInfo lookForDiff(GArray* textTokens, GArray* searchTokens, size_t iText, size_t iSearch, int maxAllowedDiff, int minTrailingMatches) { size_t searchLength = searchTokens->len; size_t textLength = textTokens->len; DiffMatchInfo result; result.diffType = NULL; size_t searchStopAt = MIN(iSearch + maxAllowedDiff, searchLength); size_t textStopAt = MIN(iText + maxAllowedDiff, textLength); for (unsigned int i = 0; i < SQUARE_VISITOR_LENGTH; i++) { result.text.start = iText + squareVisitorX[i]; result.search.start = iSearch + squareVisitorY[i]; if ((result.text.start > textStopAt) || (result.search.start > searchStopAt)) break; if ((result.text.start < textStopAt) && (result.search.start < searchStopAt)) if (matchNTokens(textTokens, result.text.start, textLength, searchTokens, result.search.start, searchLength, minTrailingMatches)) goto diffFound; } result.diffSize = -1; result.search.start = iSearch; result.search.length = 0; result.text.start = iText; result.text.length = 0; return result; diffFound: result.diffSize = MAX((result.search.start - iSearch), (result.text.start - iText)); result.search.length = result.search.start - iSearch; result.text.length = result.text.start - iText; return result; }
/* profiling says there is no need to cache the comparison */ static int licenseIncludes(const License* big, const License* small) { const GArray* tokensBig = big->tokens; const GArray* tokensSmall = small->tokens; const guint bigLen = tokensBig->len; const guint smallLen = tokensSmall->len; if (smallLen == 0) { return 1; } if (smallLen > bigLen) { return 0; } for (guint i = 0; i < bigLen; i++) { unsigned n = smallLen; if (matchNTokens(tokensBig, i, bigLen, tokensSmall, 0, smallLen, n)) { return 1; } } return 0; }