perf(processors/task): remove redundant loop
All checks were successful
build / build (push) Successful in 2m34s
build / build (pull_request) Successful in 2m32s

This commit is contained in:
李衍志523370910113 2025-03-03 16:17:32 +08:00
parent 45a184521e
commit df76f63a43
3 changed files with 128 additions and 87 deletions

View File

@ -31,11 +31,21 @@ def get_conf_stage(
] ]
), ),
) )
fix_result_detail(task_stage, conf_stage) keyword_parser = ["clangtidy", "keyword", "cppcheck", "cpplint"]
fix_dummy(task_stage, conf_stage) dummy_parser = ["dummy", "result-status"]
fix_keyword(task_stage, conf_stage) for parser in task_stage.parsers:
fix_file(task_stage, conf_stage) if parser in keyword_parser:
fix_diff(task_stage, task_conf, conf_stage) fix_keyword(task_stage, conf_stage, parser)
elif parser in dummy_parser:
fix_dummy(task_stage, conf_stage, parser)
elif parser == "result-detail":
fix_result_detail(task_stage, conf_stage, parser)
elif parser == "file":
fix_file(task_stage, conf_stage, parser)
elif parser == "diff":
fix_diff(task_stage, task_conf, conf_stage, parser)
else:
continue
return conf_stage return conf_stage
@ -70,42 +80,36 @@ def get_executor_with(task_stage: task.Stage, cached: Set[str]) -> result.Execut
def fix_keyword( def fix_keyword(
task_stage: task.Stage, conf_stage: result.StageDetail task_stage: task.Stage, conf_stage: result.StageDetail, parser: str
) -> result.StageDetail: ) -> result.StageDetail:
keyword_parser = ["clangtidy", "keyword", "cppcheck", "cpplint"] keyword_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
for parser in task_stage.parsers: keyword_weight: List[result.KeywordConfig] = []
if parser in keyword_parser: if parser in task_stage.__dict__:
keyword_parser_ = next(p for p in conf_stage.parsers if p.name == parser) unique_weight = list(set(task_stage.__dict__[parser].weight))
keyword_weight: List[result.KeywordConfig] = [] for score in unique_weight:
if parser in task_stage.__dict__: keyword_weight.append(result.KeywordConfig(keywords=[], score=score))
unique_weight = list(set(task_stage.__dict__[parser].weight))
for score in unique_weight: for idx, score in enumerate(unique_weight):
keyword_weight.append( for idx_, score_ in enumerate(task_stage.__dict__[parser].weight):
result.KeywordConfig(keywords=[], score=score) if score == score_:
keyword_weight[idx].keywords.append(
task_stage.__dict__[parser].keyword[idx_]
) )
else:
continue
for idx, score in enumerate(unique_weight): keyword_parser_.with_.update(
for idx_, score_ in enumerate(task_stage.__dict__[parser].weight): result.KeywordMatchConfig(
if score == score_: matches=keyword_weight,
keyword_weight[idx].keywords.append( ).model_dump(by_alias=True)
task_stage.__dict__[parser].keyword[idx_] )
)
else:
continue
else:
continue
keyword_parser_.with_.update(
result.KeywordMatchConfig(
matches=keyword_weight,
).model_dump(by_alias=True)
)
return conf_stage return conf_stage
def fix_result_detail(task_stage: task.Stage, conf_stage: result.StageDetail) -> None: def fix_result_detail(
if "result-detail" not in task_stage.parsers: task_stage: task.Stage, conf_stage: result.StageDetail, parser: str
return ) -> None:
result_detail_parser = next( result_detail_parser = next(
p for p in conf_stage.parsers if p.name == "result-detail" p for p in conf_stage.parsers if p.name == "result-detail"
) )
@ -126,48 +130,40 @@ def fix_result_detail(task_stage: task.Stage, conf_stage: result.StageDetail) ->
) )
def fix_dummy(task_stage: task.Stage, conf_stage: result.StageDetail) -> None: def fix_dummy(
dummy_parser = [ task_stage: task.Stage, conf_stage: result.StageDetail, parser: str
"dummy", ) -> None:
"result-status", dummy_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
] if parser.replace("-", "_") not in task_stage.__dict__:
for parser in task_stage.parsers: return
if parser not in dummy_parser: if task_stage.result_status is None:
continue return
dummy_parser_ = next(p for p in conf_stage.parsers if p.name == parser) dummy_parser_.with_.update(
if parser.replace("-", "_") not in task_stage.__dict__: result.DummyConfig(
continue score=task_stage.result_status.score,
if task_stage.result_status is None: comment=task_stage.result_status.comment,
continue force_quit_on_not_accepted=task_stage.result_status.force_quit,
dummy_parser_.with_.update( ).model_dump(by_alias=True)
result.DummyConfig( )
score=task_stage.result_status.score,
comment=task_stage.result_status.comment,
force_quit_on_not_accepted=task_stage.result_status.force_quit,
).model_dump(by_alias=True)
)
return return
def fix_file(task_stage: task.Stage, conf_stage: result.StageDetail) -> None: def fix_file(
file_parser = ["file"] task_stage: task.Stage, conf_stage: result.StageDetail, parser: str
for parser in task_stage.parsers: ) -> None:
if parser not in file_parser: file_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
continue file_parser_.with_.update(
file_parser_ = next(p for p in conf_stage.parsers if p.name == parser) result.FileConfig(name=task_stage.file.name).model_dump(by_alias=True)
file_parser_.with_.update( )
result.FileConfig(name=task_stage.file.name).model_dump(by_alias=True)
)
def fix_diff( def fix_diff(
task_stage: task.Stage, task_stage: task.Stage,
task_conf: task.Config, task_conf: task.Config,
conf_stage: result.StageDetail, conf_stage: result.StageDetail,
parser: str,
) -> None: ) -> None:
if "diff" not in task_stage.parsers: diff_parser = next((p for p in conf_stage.parsers if p.name == parser), None)
return
diff_parser = next((p for p in conf_stage.parsers if p.name == "diff"), None)
skip = task_stage.skip skip = task_stage.skip
cases = task_stage.cases cases = task_stage.cases
finalized_cases = [case for case in cases if case not in skip] finalized_cases = [case for case in cases if case not in skip]

View File

@ -222,11 +222,11 @@
} }
}, },
"copyInCached": { "copyInCached": {
"h7/build/ex2": "h7/build/ex2", "h7/build/compile_commands.json": "h7/build/compile_commands.json",
"h7/build/ex2-asan": "h7/build/ex2-asan",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-msan": "h7/build/ex2-msan", "h7/build/ex2-msan": "h7/build/ex2-msan",
"h7/build/compile_commands.json": "h7/build/compile_commands.json" "h7/build/ex2": "h7/build/ex2",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-asan": "h7/build/ex2-asan"
}, },
"copyInDir": ".", "copyInDir": ".",
"copyOut": [ "copyOut": [
@ -322,11 +322,11 @@
} }
}, },
"copyInCached": { "copyInCached": {
"h7/build/ex2": "h7/build/ex2", "h7/build/compile_commands.json": "h7/build/compile_commands.json",
"h7/build/ex2-asan": "h7/build/ex2-asan",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-msan": "h7/build/ex2-msan", "h7/build/ex2-msan": "h7/build/ex2-msan",
"h7/build/compile_commands.json": "h7/build/compile_commands.json" "h7/build/ex2": "h7/build/ex2",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-asan": "h7/build/ex2-asan"
}, },
"copyInDir": ".", "copyInDir": ".",
"copyOut": [ "copyOut": [
@ -444,11 +444,11 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": {}, "copyIn": {},
"copyInCached": { "copyInCached": {
"h7/build/ex2": "h7/build/ex2", "h7/build/compile_commands.json": "h7/build/compile_commands.json",
"h7/build/ex2-asan": "h7/build/ex2-asan",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-msan": "h7/build/ex2-msan", "h7/build/ex2-msan": "h7/build/ex2-msan",
"h7/build/compile_commands.json": "h7/build/compile_commands.json" "h7/build/ex2": "h7/build/ex2",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-asan": "h7/build/ex2-asan"
}, },
"copyInDir": ".", "copyInDir": ".",
"copyOut": [ "copyOut": [
@ -467,6 +467,12 @@
} }
}, },
"parsers": [ "parsers": [
{
"name": "keyword",
"with": {
"matches": []
}
},
{ {
"name": "cppcheck", "name": "cppcheck",
"with": { "with": {
@ -489,6 +495,10 @@
] ]
} }
}, },
{
"name": "clang-tidy",
"with": {}
},
{ {
"name": "result-detail", "name": "result-detail",
"with": { "with": {
@ -501,6 +511,41 @@
"showRuntime": false, "showRuntime": false,
"showMemory": false "showMemory": false
} }
},
{
"name": "cpplint",
"with": {
"matches": []
}
},
{
"name": "result-status",
"with": {
"score": 0,
"comment": "",
"forceQuitOnNotAccepted": false
}
},
{
"name": "file",
"with": {
"name": ""
}
},
{
"name": "dummy",
"with": {
"score": 0,
"comment": "",
"forceQuitOnNotAccepted": false
}
},
{
"name": "diff",
"with": {
"name": "diff",
"cases": []
}
} }
] ]
}, },
@ -542,11 +587,11 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": {}, "copyIn": {},
"copyInCached": { "copyInCached": {
"h7/build/ex2": "h7/build/ex2", "h7/build/compile_commands.json": "h7/build/compile_commands.json",
"h7/build/ex2-asan": "h7/build/ex2-asan",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-msan": "h7/build/ex2-msan", "h7/build/ex2-msan": "h7/build/ex2-msan",
"h7/build/compile_commands.json": "h7/build/compile_commands.json" "h7/build/ex2": "h7/build/ex2",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-asan": "h7/build/ex2-asan"
}, },
"copyInDir": ".", "copyInDir": ".",
"copyOut": [ "copyOut": [
@ -639,11 +684,11 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": {}, "copyIn": {},
"copyInCached": { "copyInCached": {
"h7/build/ex2": "h7/build/ex2", "h7/build/compile_commands.json": "h7/build/compile_commands.json",
"h7/build/ex2-asan": "h7/build/ex2-asan",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-msan": "h7/build/ex2-msan", "h7/build/ex2-msan": "h7/build/ex2-msan",
"h7/build/compile_commands.json": "h7/build/compile_commands.json" "h7/build/ex2": "h7/build/ex2",
"h7/build/ex2-ubsan": "h7/build/ex2-ubsan",
"h7/build/ex2-asan": "h7/build/ex2-asan"
}, },
"copyInDir": ".", "copyInDir": ".",
"copyOut": [ "copyOut": [

View File

@ -53,7 +53,7 @@ name = "[cq] Cppcheck"
command = "cppcheck --template='{\"file\":\"{file}\",\"line\":{line}, \"column\":{column}, \"severity\":\"{severity}\", \"message\":\"{message}\", \"id\":\"{id}\"}' --force --enable=all --suppress=missingIncludeSystem --quiet h7/ex2.cpp" command = "cppcheck --template='{\"file\":\"{file}\",\"line\":{line}, \"column\":{column}, \"severity\":\"{severity}\", \"message\":\"{message}\", \"id\":\"{id}\"}' --force --enable=all --suppress=missingIncludeSystem --quiet h7/ex2.cpp"
limit.stderr = "8m" limit.stderr = "8m"
parsers = [ "cppcheck", "result-detail" ] parsers = [ "keyword", "cppcheck", "clang-tidy", "result-detail", "cpplint", "result-status", "file", "dummy", "diff" ]
cppcheck.keyword = ["error", "warning", "portability", "performance", "style"] cppcheck.keyword = ["error", "warning", "portability", "performance", "style"]
cppcheck.weight = [15, 5, 5, 5, 5] cppcheck.weight = [15, 5, 5, 5, 5]
result-detail.exitstatus = true result-detail.exitstatus = true