From 870995933a60b67af03b3f42a2aed169d33bd87f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 12 Mar 2018 03:35:11 +0100 Subject: Remove redundant Date.now() --- packages/sol-cov/src/collect_coverage_entries.ts | 24 +++++++++++++++++++++++ packages/sol-cov/src/coverage_manager.ts | 2 +- packages/sol-cov/src/instrument_solidity.ts | 25 ------------------------ 3 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 packages/sol-cov/src/collect_coverage_entries.ts delete mode 100644 packages/sol-cov/src/instrument_solidity.ts (limited to 'packages/sol-cov/src') diff --git a/packages/sol-cov/src/collect_coverage_entries.ts b/packages/sol-cov/src/collect_coverage_entries.ts new file mode 100644 index 000000000..d29fa2c37 --- /dev/null +++ b/packages/sol-cov/src/collect_coverage_entries.ts @@ -0,0 +1,24 @@ +import * as ethUtil from 'ethereumjs-util'; +import * as fs from 'fs'; +import * as _ from 'lodash'; +import * as path from 'path'; +import * as SolidityParser from 'solidity-parser-sc'; + +import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor'; +import { getLocationByOffset } from './source_maps'; + +// Parsing source code for each transaction/code is slow and therefore we cache it +const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {}; + +export const collectCoverageEntries = (contractSource: string, fileName: string) => { + const sourceHash = ethUtil.sha3(contractSource).toString('hex'); + if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) { + const ast = SolidityParser.parse(contractSource); + const locationByOffset = getLocationByOffset(contractSource); + const astVisitor = new ASTVisitor(locationByOffset); + astVisitor.walkAST(ast); + coverageEntriesBySourceHash[sourceHash] = astVisitor.getCollectedCoverageEntries(); + } + const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash]; + return coverageEntriesDescription; +}; diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts index 870dc2bdb..4ca6b0ec8 100644 --- a/packages/sol-cov/src/coverage_manager.ts +++ b/packages/sol-cov/src/coverage_manager.ts @@ -4,8 +4,8 @@ import * as _ from 'lodash'; import * as path from 'path'; import { collectContractsData } from './collect_contract_data'; +import { collectCoverageEntries } from './collect_coverage_entries'; import { constants } from './constants'; -import { collectCoverageEntries } from './instrument_solidity'; import { parseSourceMap } from './source_maps'; import { BranchCoverage, diff --git a/packages/sol-cov/src/instrument_solidity.ts b/packages/sol-cov/src/instrument_solidity.ts deleted file mode 100644 index 163e3c7b9..000000000 --- a/packages/sol-cov/src/instrument_solidity.ts +++ /dev/null @@ -1,25 +0,0 @@ -import * as ethUtil from 'ethereumjs-util'; -import * as fs from 'fs'; -import * as _ from 'lodash'; -import * as path from 'path'; -import * as SolidityParser from 'solidity-parser-sc'; - -import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor'; -import { getLocationByOffset } from './source_maps'; - -// Parsing source code for each transaction/code is slow and therefore we cache it -const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {}; - -export const collectCoverageEntries = (contractSource: string, fileName: string) => { - const time = Date.now(); - const sourceHash = ethUtil.sha3(contractSource).toString('hex'); - if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) { - const ast = SolidityParser.parse(contractSource); - const locationByOffset = getLocationByOffset(contractSource); - const astVisitor = new ASTVisitor(locationByOffset); - astVisitor.walkAST(ast); - coverageEntriesBySourceHash[sourceHash] = astVisitor.getCollectedCoverageEntries(); - } - const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash]; - return coverageEntriesDescription; -}; -- cgit