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

add warnings for known useless / avoidable memory-allocations (especially in phobos) #929

Open
9 tasks
WebFreak001 opened this issue Sep 4, 2023 · 1 comment

Comments

@WebFreak001
Copy link
Member

WebFreak001 commented Sep 4, 2023

Known useless extra allocations (can be removed without any downsides):

  • std.array:array on SortedRange!(T[]) -> use .release (avoids allocation) or .dup (keeps behavior) instead
  • std.array:array on result of joiner -> use join

Known extra allocations that might be there for a reason:

  • any function taking both string and string range - only warning in trivial cases with simple strings as arguments, since other types and ranges may not be evaluatable twice - suggest replacement function (avoids allocation) or use new local string variable (keeps behavior)
    • std.path : buildPath -> chainPath
    • std.utf : toUTF8 -> byUTF!char
    • std.utf : toUTF16 -> byUTF!wchar
    • std.utf : toUTF32 -> byUTF!dchar
    • std.uni : toLower -> asLowerCase
    • std.uni : toUpper -> asUpperCase
@WebFreak001
Copy link
Member Author

WebFreak001 commented Sep 4, 2023

cc @ljmf00 this might actually be something that should be trivial to implement in ldclint, where you could even accurately check for InputRange/ForwardRange and actually also warn on cases that D-Scanner wouldn't easily be able to tell apart and would just leave out to avoid false positives.

Although we are likely still going to implement this in D-Scanner anyway, with its not full accurate, but much less RAM using dsymbol index, while ldclint isn't fully ready to be used yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant