<commit_before>import Domain = CompletersNS.Domain;
import MatchType = CompletersNS.MatchType;

setTimeout((function (): void {

type MatchRange = [number, number];

interface DecodedItem {
  readonly url: string;
  text: string;
}

interface Bookmark extends DecodedItem {
  readonly url: string;
  readonly text: string;
  readonly path: string;
  readonly title: string;
}
interface JSBookmark extends Bookmark {
  readonly jsUrl: string;
  readonly jsText: string;
}
interface PureHistoryItem {
  lastVisitTime: number;
  title: string;
  readonly url: string;
}
interface HistoryItem extends DecodedItem, PureHistoryItem {
}
interface UrlItem {
  url: string;
  title: string;
  sessionId?: string | number;
}

interface TextTab extends chrome.tabs.Tab {
  text: string;  
}

interface Completer {
  filter(query: CompletersNS.QueryStatus, index: number): void;
}
interface PreCompleter extends Completer {
  preFilter(query: CompletersNS.QueryStatus, failIfNull: true): void | true;
  preFilter(query: CompletersNS.QueryStatus): void;
}
interface QueryTerms extends Array<string> {
  more?: string;
}

const enum FirstQuery {
  nothing = 0,
  waitFirst = 1,
  searchEngines = 2,
  history = 3,
  tabs = 4,

  QueryTypeMask = 63,
  historyIncluded = 67,
}

interface SuggestionConstructor {
  new (type: string, url: string, text: string, title: string,
        computeRelevancy: (this: void, sug: CompletersNS.CoreSuggestion, data?: number) => number,
        extraData?: number): Suggestion;
}

const enum RegExpCacheIndex {
  word = 0, start = 1, part = 2
}
type CachedRegExp = (RegExpOne | RegExpI) & RegExpSearchable<0>;
type RegExpCacheDict = [SafeDict<CachedRegExp>, SafeDict<CachedRegExp>, SafeDict<CachedRegExp>];

type HistoryCallback = (history: ReadonlyArray<HistoryItem>) => any;

interface UrlToDecode extends String {
  url?: void;
}
type ItemToDecode = UrlToDecode | DecodedItem;

type CompletersMap = {
    [P in CompletersNS.ValidTypes]: ReadonlyArray<Completer>;
};
interface WindowEx extends Window {
  Completers: CompletersMap & GlobalCompletersConstructor;
}
type SearchSuggestion = CompletersNS.SearchSuggestion;


let queryType: FirstQuery, offset: number, autoSelect: boolean,
    maxCharNum: number, maxResults: number, maxTotal: number, matchType: MatchType,
    queryTerms: QueryTerms;

const Suggestion: SuggestionConstructor = function (this: CompletersNS.WritableCoreSuggestion,
    type: CompletersNS.ValidSugTypes, url: string, text: string, title: string,
    computeRelevancy: (this: void, sug: CompletersNS.CoreSuggestion, data?: number) => number, extraData?: number
    ) {
  this.type = type;
  this.url = url;
  this.text = text;
  this.title = title;
  (this as Suggestion).relevancy = computeRelevancy(this, extraData);
} as any;

const SuggestionUtils = {
  prepareHtml (sug: Suggestion): void {
    if (sug.textSplit != null) {
      if (sug.text === sug.url) { sug.text = ""; }
      return;
    }
    sug.title = this.highlight(sug.title, this.getRanges(sug.title));
    const text = sug.text, str = this.shortenUrl(text);
    sug.text = text !== sug.url ? str : "";
    sug.textSplit = this.cutUrl(str, this.getRanges(str), sug.url);
  },
  highlight (this: void, string: string, ranges: number[]): string {
    let out: string[], end: number;
    if (ranges.length === 0) { return Utils.escapeText(string); }
    out = []; end = 0;
    for(let _i = 0; _i < ranges.length; _i += 2) {<commit_msg>cut sug.title to avoid bad performance<commit_after>import Domain = CompletersNS.Domain;
import MatchType = CompletersNS.MatchType;

setTimeout((function (): void {

type MatchRange = [number, number];

interface DecodedItem {
  readonly url: string;
  text: string;
}

interface Bookmark extends DecodedItem {
  readonly url: string;
  readonly text: string;
  readonly path: string;
  readonly title: string;
}
interface JSBookmark extends Bookmark {
  readonly jsUrl: string;
  readonly jsText: string;
}
interface PureHistoryItem {
  lastVisitTime: number;
  title: string;
  readonly url: string;
}
interface HistoryItem extends DecodedItem, PureHistoryItem {
}
interface UrlItem {
  url: string;
  title: string;
  sessionId?: string | number;
}

interface TextTab extends chrome.tabs.Tab {
  text: string;  
}

interface Completer {
  filter(query: CompletersNS.QueryStatus, index: number): void;
}
interface PreCompleter extends Completer {
  preFilter(query: CompletersNS.QueryStatus, failIfNull: true): void | true;
  preFilter(query: CompletersNS.QueryStatus): void;
}
interface QueryTerms extends Array<string> {
  more?: string;
}

const enum FirstQuery {
  nothing = 0,
  waitFirst = 1,
  searchEngines = 2,
  history = 3,
  tabs = 4,

  QueryTypeMask = 63,
  historyIncluded = 67,
}

interface SuggestionConstructor {
  new (type: string, url: string, text: string, title: string,
        computeRelevancy: (this: void, sug: CompletersNS.CoreSuggestion, data?: number) => number,
        extraData?: number): Suggestion;
}

const enum RegExpCacheIndex {
  word = 0, start = 1, part = 2
}
type CachedRegExp = (RegExpOne | RegExpI) & RegExpSearchable<0>;
type RegExpCacheDict = [SafeDict<CachedRegExp>, SafeDict<CachedRegExp>, SafeDict<CachedRegExp>];

type HistoryCallback = (history: ReadonlyArray<HistoryItem>) => any;

interface UrlToDecode extends String {
  url?: void;
}
type ItemToDecode = UrlToDecode | DecodedItem;

type CompletersMap = {
    [P in CompletersNS.ValidTypes]: ReadonlyArray<Completer>;
};
interface WindowEx extends Window {
  Completers: CompletersMap & GlobalCompletersConstructor;
}
type SearchSuggestion = CompletersNS.SearchSuggestion;


let queryType: FirstQuery, offset: number, autoSelect: boolean,
    maxCharNum: number, maxResults: number, maxTotal: number, matchType: MatchType,
    queryTerms: QueryTerms;

const Suggestion: SuggestionConstructor = function (this: CompletersNS.WritableCoreSuggestion,
    type: CompletersNS.ValidSugTypes, url: string, text: string, title: string,
    computeRelevancy: (this: void, sug: CompletersNS.CoreSuggestion, data?: number) => number, extraData?: number
    ) {
  this.type = type;
  this.url = url;
  this.text = text;
  this.title = title;
  (this as Suggestion).relevancy = computeRelevancy(this, extraData);
} as any;

const SuggestionUtils = {
  prepareHtml (sug: Suggestion): void {
    if (sug.textSplit != null) {
      if (sug.text === sug.url) { sug.text = ""; }
      return;
    }
    sug.title = this.cutTitle(sug.title);
    const text = sug.text, str = this.shortenUrl(text);
    sug.text = text !== sug.url ? str : "";
    sug.textSplit = this.cutUrl(str, this.getRanges(str), sug.url);
  },
  cutTitle (title: string): string {
    title = title.length > 128 ? title.substring(0, 125) + "..." : title;
    return this.highlight(title, this.getRanges(title));
  },
  highlight (this: void, string: string, ranges: number[]): string {
    let out: string[], end: number;
    if (ranges.length === 0) { return Utils.escapeText(string); }
    out = []; end = 0;
    for(let _i = 0; _i < ranges.length; _i += 2) {
{'fraction_non_alphanumeric': 0.11703934333427682, 'fraction_numerical': 0.005802434191904897, 'mean_word_length': 4.419478527607362, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2609049', 'n_tokens_mistral': 2343, 'n_tokens_neox': 2284, 'n_words': 623}