libclang 翻译单元的重新解析速度较慢
我有一个 C++ 文件,它会更改,其余所有头文件保持不变。但每当我重新解析翻译单元时,libclang 最终都会消耗大量的 cpu 和 ram。尽管它使用预编译头和所有内容(我可以看到生成的前导文件),但仍然需要相当多的资源和时间。
这是我的代码片段。
translation_unit_ = clang_parseTranslationUnit(index_, 0, clang_argv[0],
clang_argv.size() - 1, 0, 0,
clang_defaultEditingTranslationUnitOptions());
// File name is in the arguments.
// Here I reparse again every time file changes.
clang_reparseTranslationUnit(translation_unit_, 0, 0,
clang_defaultReparseOptions(translation_unit_));
// This is how I get diagnositics
CXDiagnostic diag = clang_getDiagnostic(translation_unit_, i);
谁能建议我正确的设置,以便在单个不断变化的源文件中重复查找编译错误?
I have a c++ file which changes and rest all headers files remain unchanged. But whenever I re-parse a translation unit, libclang ends up consuming lots of cpu and ram. Although it is using precompiled header and all (I can see preamble files generated) but still it takes quite bit of resources as well as time.
Here is the snippet of my code.
translation_unit_ = clang_parseTranslationUnit(index_, 0, clang_argv[0],
clang_argv.size() - 1, 0, 0,
clang_defaultEditingTranslationUnitOptions());
// File name is in the arguments.
// Here I reparse again every time file changes.
clang_reparseTranslationUnit(translation_unit_, 0, 0,
clang_defaultReparseOptions(translation_unit_));
// This is how I get diagnositics
CXDiagnostic diag = clang_getDiagnostic(translation_unit_, i);
Can anyone suggest me right setup for finding compile errors in a single changing source file repeatedly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在初始索引中使用
clang_defaultEditingTranslationUnitOptions()
,稍后使用clang_defaultReparseOptions()
。尝试在这两个地方使用clang_defaultEditingTranslationUnitOptions()
。另外,不要指望重新解析源代码会非常快 - 重新检查每一个更改将导致任何重要源文件的性能不佳。您能否在最后一次更改后等待几毫秒,看看是否可以将多个更改累积到一次重新分析中?
You're using
clang_defaultEditingTranslationUnitOptions()
in the initial indexing andclang_defaultReparseOptions()
later. Try usingclang_defaultEditingTranslationUnitOptions()
in both places.Also, don't expect reparsing the source to be extremely quick - rechecking every single change will lead to poor performance in any non-trivial source file. Can you wait a few milliseconds after the last change, to see if you can accumulate multiple changes into a single reparse?