[12743] Fix some static code analysis warnings and improve performance