Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History_Manager: Move static variable to outside of fucntion #998

Conversation

ma8ma
Copy link
Collaborator

@ma8ma ma8ma commented Jun 11, 2022

変数のスコープ範囲を減らすことができるとcppcheck 2.8に指摘されたため静的変数を関数の外に移動します。

style: The scope of the variable 'nullitems' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:

void f(int x)
{
    int i = 0;
    if (x) {
        // it's safe to move 'int i = 0;' here
        for (int n = 0; n < 10; ++n) {
            // it is possible but not safe to move 'int i = 0;' here
            do_something(&i);
        }
    }
}

When you see this message it is always safe to reduce the variable scope 1 level. [variableScope]

src/history/historymanager.cpp:467:44: style: The scope of the variable 'nullitems' can be reduced. (snip) [variableScope]
    static std::vector< ViewHistoryItem* > nullitems;
                                           ^
src/history/historymanager.cpp:478:44: style: The scope of the variable 'nullitems' can be reduced. (snip) [variableScope]
    static std::vector< ViewHistoryItem* > nullitems;
                                           ^

関連のpull request: #988

変数のスコープ範囲を減らすことができるとcppcheck 2.8に指摘されたため
静的変数を関数の外に移動します。

> style: The scope of the variable 'nullitems' can be reduced.
> Warning: Be careful when fixing this message, especially when
> there are inner loops. Here is an example where cppcheck will
> write that the scope for 'i' can be reduced:
>
> void f(int x)
> {
>     int i = 0;
>     if (x) {
>         // it's safe to move 'int i = 0;' here
>         for (int n = 0; n < 10; ++n) {
>             // it is possible but not safe to move 'int i = 0;' here
>             do_something(&i);
>         }
>     }
> }
>
> When you see this message it is always safe to reduce the variable
> scope 1 level. [variableScope]

```
src/history/historymanager.cpp:467:44: style: The scope of the variable 'nullitems' can be reduced. (snip) [variableScope]
    static std::vector< ViewHistoryItem* > nullitems;
                                           ^
src/history/historymanager.cpp:478:44: style: The scope of the variable 'nullitems' can be reduced. (snip) [variableScope]
    static std::vector< ViewHistoryItem* > nullitems;
                                           ^
```
@ma8ma ma8ma added the refactoring コードの整理 (バグ修正でも機能変更でもない) label Jun 11, 2022
@ma8ma ma8ma merged commit e4bad5a into JDimproved:master Jun 11, 2022
@ma8ma ma8ma deleted the historymanager-move-static-var-to-outside-function branch June 11, 2022 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring コードの整理 (バグ修正でも機能変更でもない)
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant