Global Metrics
path: .metrics.loc.cloc
old: 513.0
new: 6.0
path: .metrics.loc.ploc
old: 2389.0
new: 177.0
path: .metrics.loc.sloc
old: 3223.0
new: 210.0
path: .metrics.loc.lloc
old: 1026.0
new: 88.0
path: .metrics.loc.blank
old: 321.0
new: 27.0
path: .metrics.halstead.volume
old: 124758.05891187866
new: 6116.482365147784
path: .metrics.halstead.N1
old: 7248.0
new: 527.0
path: .metrics.halstead.effort
old: 11267505.22254225
new: 315610.4900416256
path: .metrics.halstead.estimated_program_length
old: 11215.88669301468
new: 811.5923368457279
path: .metrics.halstead.N2
old: 5053.0
new: 344.0
path: .metrics.halstead.purity_ratio
old: 0.9117865777590992
new: 0.931793727721846
path: .metrics.halstead.n1
old: 39.0
new: 30.0
path: .metrics.halstead.length
old: 12301.0
new: 871.0
path: .metrics.halstead.n2
old: 1091.0
new: 100.0
path: .metrics.halstead.time
old: 625972.5123634584
new: 17533.916113423646
path: .metrics.halstead.vocabulary
old: 1130.0
new: 130.0
path: .metrics.halstead.difficulty
old: 90.31484876260312
new: 51.6
path: .metrics.halstead.level
old: 0.0110723763999046
new: 0.01937984496124031
path: .metrics.halstead.bugs
old: 16.753180101406713
new: 1.5451822062172256
path: .metrics.nargs.sum
old: 199.0
new: 20.0
path: .metrics.nargs.average
old: 2.139784946236559
new: 1.3333333333333333
path: .metrics.nom.total
old: 93.0
new: 15.0
path: .metrics.nom.closures
old: 5.0
new: 0.0
path: .metrics.nom.functions
old: 88.0
new: 15.0
path: .metrics.mi.mi_sei
old: -224.74451445726808
new: -17.70495654984057
path: .metrics.mi.mi_original
old: -168.77218406793105
new: 27.76939734910185
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 16.239413654445528
path: .metrics.cognitive.average
old: 8.731182795698924
new: 3.4
path: .metrics.cognitive.sum
old: 812.0
new: 51.0
path: .metrics.nexits.average
old: 1.1720430107526882
new: 1.2666666666666666
path: .metrics.nexits.sum
old: 109.0
new: 19.0
path: .metrics.cyclomatic.average
old: 7.144444444444445
new: 2.8823529411764706
path: .metrics.cyclomatic.sum
old: 643.0
new: 49.0
Spaces Data
Minimal test - lines (11, 210)
path: .spaces[0].metrics.cyclomatic.sum
old: 3.0
new: 48.0
path: .spaces[0].metrics.mi.mi_visual_studio
old: 60.36403227019445
new: 16.86125229997022
path: .spaces[0].metrics.mi.mi_original
old: 103.2224951820325
new: 28.83274143294908
path: .spaces[0].metrics.mi.mi_sei
old: 108.49458301667632
new: -29.216645660049224
path: .spaces[0].metrics.cognitive.average
old: 3.0
new: 3.4
path: .spaces[0].metrics.cognitive.sum
old: 3.0
new: 51.0
path: .spaces[0].metrics.halstead.length
old: 41.0
new: 868.0
path: .spaces[0].metrics.halstead.n1
old: 9.0
new: 30.0
path: .spaces[0].metrics.halstead.n2
old: 10.0
new: 97.0
path: .spaces[0].metrics.halstead.N1
old: 24.0
new: 527.0
path: .spaces[0].metrics.halstead.bugs
old: 0.0403608531768034
new: 1.559090991911237
path: .spaces[0].metrics.halstead.vocabulary
old: 19.0
new: 127.0
path: .spaces[0].metrics.halstead.estimated_program_length
old: 61.74860596185444
new: 787.398263560407
path: .spaces[0].metrics.halstead.effort
old: 1332.3624645915806
new: 319881.4643920082
path: .spaces[0].metrics.halstead.difficulty
old: 7.65
new: 52.7319587628866
path: .spaces[0].metrics.halstead.time
old: 74.02013692175449
new: 17771.192466222677
path: .spaces[0].metrics.halstead.level
old: 0.13071895424836602
new: 0.018963831867057673
path: .spaces[0].metrics.halstead.N2
old: 17.0
new: 341.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.50606356004523
new: 0.9071408566364136
path: .spaces[0].metrics.halstead.volume
old: 174.165028051187
new: 6066.178308118239
path: .spaces[0].metrics.loc.ploc
old: 9.0
new: 174.0
path: .spaces[0].metrics.loc.sloc
old: 12.0
new: 200.0
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 26.0
path: .spaces[0].metrics.loc.lloc
old: 4.0
new: 88.0
path: .spaces[0].metrics.loc.cloc
old: 3.0
new: 0.0
path: .spaces[0].metrics.nargs.sum
old: 3.0
new: 20.0
path: .spaces[0].metrics.nargs.average
old: 3.0
new: 1.3333333333333333
path: .spaces[0].metrics.nexits.average
old: 0.0
new: 1.2666666666666666
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 19.0
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 15.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 15.0
Code
namespace mozilla {
FileLocation::FileLocation() = default;
FileLocation::~FileLocation() = default;
FileLocation::FileLocation(nsIFile* aFile) { Init(aFile); }
FileLocation::FileLocation(nsIFile* aFile, const char* aPath) {
Init(aFile, aPath);
}
FileLocation::FileLocation(nsZipArchive* aZip, const char* aPath) {
Init(aZip, aPath);
}
FileLocation::FileLocation(const FileLocation& aOther)
= default;
FileLocation::FileLocation(FileLocation&& aOther)
: mBaseFile(std::move(aOther.mBaseFile)),
mBaseZip(std::move(aOther.mBaseZip)),
mPath(std::move(aOther.mPath)) {
aOther.mPath.Truncate();
}
FileLocation::FileLocation(const FileLocation& aFile, const char* aPath) {
if (aFile.IsZip()) {
if (aFile.mBaseFile) {
Init(aFile.mBaseFile, aFile.mPath.get());
} else {
Init(aFile.mBaseZip, aFile.mPath.get());
}
if (aPath) {
int32_t i = mPath.RFindChar('/');
if (kNotFound == i) {
mPath.Truncate(0);
} else {
mPath.Truncate(i + 1);
}
mPath += aPath;
}
} else {
if (aPath) {
nsCOMPtr cfile;
aFile.mBaseFile->GetParent(getter_AddRefs(cfile));
#if defined(XP_WIN)
nsAutoCString pathStr(aPath);
char* p;
uint32_t len = pathStr.GetMutableData(&p);
for (; len; ++p, --len) {
if ('/' == *p) {
*p = '\\';
}
}
cfile->AppendRelativeNativePath(pathStr);
#else
cfile->AppendRelativeNativePath(nsDependentCString(aPath));
#endif
Init(cfile);
} else {
Init(aFile.mBaseFile);
}
}
}
void FileLocation::Init(nsIFile* aFile) {
mBaseZip = nullptr;
mBaseFile = aFile;
mPath.Truncate();
}
void FileLocation::Init(nsIFile* aFile, const char* aPath) {
mBaseZip = nullptr;
mBaseFile = aFile;
mPath = aPath;
}
void FileLocation::Init(nsZipArchive* aZip, const char* aPath) {
mBaseZip = aZip;
mBaseFile = nullptr;
mPath = aPath;
}
void FileLocation::GetURIString(nsACString& aResult) const {
if (mBaseFile) {
net_GetURLSpecFromActualFile(mBaseFile, aResult);
} else if (mBaseZip) {
RefPtr handler = mBaseZip->GetFD();
handler->mFile.GetURIString(aResult);
}
if (IsZip()) {
aResult.InsertLiteral("jar:", 0);
aResult += "!/";
aResult += mPath;
}
}
already_AddRefed FileLocation::GetBaseFile() {
if (IsZip() && mBaseZip) {
RefPtr handler = mBaseZip->GetFD();
if (handler) {
return handler->mFile.GetBaseFile();
}
return nullptr;
}
nsCOMPtr file = mBaseFile;
return file.forget();
}
bool FileLocation::Equals(const FileLocation& aFile) const {
if (mPath != aFile.mPath) {
return false;
}
if (mBaseFile && aFile.mBaseFile) {
bool eq;
return NS_SUCCEEDED(mBaseFile->Equals(aFile.mBaseFile, &eq)) && eq;
}
const FileLocation* a = this;
const FileLocation* b = &aFile;
if (a->mBaseZip) {
RefPtr handler = a->mBaseZip->GetFD();
a = &handler->mFile;
}
if (b->mBaseZip) {
RefPtr handler = b->mBaseZip->GetFD();
b = &handler->mFile;
}
return a->Equals(*b);
}
nsresult FileLocation::GetData(Data& aData) {
if (!IsZip()) {
return mBaseFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &aData.mFd.rwget());
}
aData.mZip = mBaseZip;
if (!aData.mZip) {
aData.mZip = new nsZipArchive();
aData.mZip->OpenArchive(mBaseFile);
}
aData.mItem = aData.mZip->GetItem(mPath.get());
if (aData.mItem) {
return NS_OK;
}
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
nsresult FileLocation::Data::GetSize(uint32_t* aResult) {
if (mFd) {
PRFileInfo64 fileInfo;
if (PR_SUCCESS != PR_GetOpenFileInfo64(mFd, &fileInfo)) {
return NS_ErrorAccordingToNSPR();
}
if (fileInfo.size > int64_t(UINT32_MAX)) {
return NS_ERROR_FILE_TOO_BIG;
}
*aResult = fileInfo.size;
return NS_OK;
}
if (mItem) {
*aResult = mItem->RealSize();
return NS_OK;
}
return NS_ERROR_NOT_INITIALIZED;
}
nsresult FileLocation::Data::Copy(char* aBuf, uint32_t aLen) {
if (mFd) {
for (uint32_t totalRead = 0; totalRead < aLen;) {
int32_t read = PR_Read(mFd, aBuf + totalRead,
XPCOM_MIN(aLen - totalRead, uint32_t(INT32_MAX)));
if (read < 0) {
return NS_ErrorAccordingToNSPR();
}
totalRead += read;
}
return NS_OK;
}
if (mItem) {
nsZipCursor cursor(mItem, mZip, reinterpret_cast(aBuf), aLen,
true);
uint32_t readLen;
cursor.Copy(&readLen);
if (readLen != aLen) {
return NS_ERROR_FILE_CORRUPTED;
}
return NS_OK;
}
return NS_ERROR_NOT_INITIALIZED;
}
} /* namespace mozilla */