-
-
Notifications
You must be signed in to change notification settings - Fork 753
std.math and std.stdio: use more selective imports #4361
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,12 @@ Authors: $(WEB digitalmars.com, Walter Bright), | |
| module std.stdio; | ||
|
|
||
| public import core.stdc.stdio; | ||
| import std.typecons;// Flag | ||
| import std.stdiobase; | ||
| import core.stdc.stddef;// wchar_t | ||
| import std.range.primitives;// empty, front, isBidirectionalRange | ||
| import std.traits;// Unqual, isSomeChar, isSomeString | ||
| import std.algorithm.mutation; // copy | ||
| import std.range.primitives;// ElementEncodingType, front, isBidirectionalRange, isInputRange | ||
| import std.stdiobase; | ||
| import std.traits;// isSomeChar, isSomeString, Unqual | ||
| import std.typecons;// Flag | ||
|
|
||
|
|
||
| /++ | ||
|
|
@@ -281,6 +282,7 @@ public: | |
| import std.conv : text; | ||
| import std.exception : enforce; | ||
| import std.format : formattedRead; | ||
| import std.range.primitives : empty; | ||
| import std.string : chomp; | ||
|
|
||
| enforce(file.isOpen, "ByRecord: File must be open"); | ||
|
|
@@ -464,7 +466,7 @@ file. | |
| */ | ||
| void opAssign(File rhs) @safe | ||
| { | ||
| import std.algorithm : swap; | ||
| import std.algorithm.mutation : swap; | ||
|
|
||
| swap(this, rhs); | ||
| } | ||
|
|
@@ -1250,8 +1252,8 @@ Removes the lock over the specified file segment. | |
| static void runForked(void delegate() code) | ||
| { | ||
| import core.stdc.stdlib : exit; | ||
| import core.sys.posix.unistd; | ||
| import core.sys.posix.sys.wait; | ||
| import core.sys.posix.sys.wait : wait; | ||
| import core.sys.posix.unistd : fork; | ||
| int child, status; | ||
| if ((child = fork()) == 0) | ||
| { | ||
|
|
@@ -1430,7 +1432,7 @@ void main() | |
| unittest | ||
| { | ||
| static import std.file; | ||
| import std.algorithm : equal; | ||
| import std.algorithm.comparison : equal; | ||
| import std.meta : AliasSeq; | ||
|
|
||
| auto deleteme = testFilename(); | ||
|
|
@@ -1622,8 +1624,9 @@ is recommended if you want to process a complete file. | |
| if (isSomeChar!C && is(Unqual!C == C) && !is(C == enum) && | ||
| isBidirectionalRange!R && is(typeof(terminator.front == dchar.init))) | ||
| { | ||
| import std.algorithm : endsWith, swap; | ||
| import std.range.primitives : back; | ||
| import std.algorithm.mutation : swap; | ||
| import std.algorithm.searching : endsWith; | ||
| import std.range.primitives : back, empty; | ||
|
|
||
| auto last = terminator.back; | ||
| C[] buf2; | ||
|
|
@@ -1779,7 +1782,7 @@ Allows to directly use range operations on lines of a file. | |
| struct ByLine(Char, Terminator) | ||
| { | ||
| private: | ||
| import std.typecons; | ||
| import std.typecons : RefCounted, RefCountedAutoInitialize; | ||
|
|
||
| /* Ref-counting stops the source range's Impl | ||
| * from getting out of sync after the range is copied, e.g. | ||
|
|
@@ -1847,7 +1850,8 @@ Allows to directly use range operations on lines of a file. | |
|
|
||
| void popFront() | ||
| { | ||
| import std.algorithm : endsWith; | ||
| import std.algorithm.searching : endsWith; | ||
| import std.range.primitives : empty; | ||
| assert(file.isOpen); | ||
| line = buffer; | ||
| file.readln(line, terminator); | ||
|
|
@@ -1975,7 +1979,7 @@ the contents may well have changed). | |
| private struct ByLineCopy(Char, Terminator) | ||
| { | ||
| private: | ||
| import std.typecons; | ||
| import std.typecons : RefCounted, RefCountedAutoInitialize; | ||
|
|
||
| /* Ref-counting stops the source range's ByLineCopyImpl | ||
| * from getting out of sync after the range is copied, e.g. | ||
|
|
@@ -2104,8 +2108,7 @@ $(XREF file,readText) | |
| unittest | ||
| { | ||
| static import std.file; | ||
| import std.algorithm : equal; | ||
| import std.range; | ||
| import std.algorithm.comparison : equal; | ||
|
|
||
| //printf("Entering test at line %d\n", __LINE__); | ||
| scope(failure) printf("Failed test at line %d\n", __LINE__); | ||
|
|
@@ -2125,8 +2128,9 @@ $(XREF file,readText) | |
| void test(Terminator)(string txt, in string[] witness, | ||
| KeepTerminator kt, Terminator term, bool popFirstLine = false) | ||
| { | ||
| import std.array : array; | ||
| import std.conv : text; | ||
| import std.algorithm : sort; | ||
| import std.algorithm.sorting : sort; | ||
| import std.range.primitives : walkLength; | ||
|
|
||
| uint i; | ||
|
|
@@ -2183,8 +2187,8 @@ $(XREF file,readText) | |
|
|
||
| unittest | ||
| { | ||
| import std.algorithm : equal; | ||
| import std.range; | ||
| import std.algorithm.comparison : equal; | ||
| import std.range : drop, take; | ||
|
|
||
| version(Win64) | ||
| { | ||
|
|
@@ -2275,6 +2279,7 @@ $(XREF file,readText) | |
| unittest | ||
| { | ||
| static import std.file; | ||
| import std.typecons : tuple; | ||
|
|
||
| // prepare test file | ||
| auto testFile = testFilename(); | ||
|
|
@@ -2318,7 +2323,7 @@ $(XREF file,readText) | |
|
|
||
| this(File file, ubyte[] buffer) | ||
| { | ||
| import std.exception; | ||
| import std.exception : enforce; | ||
| enforce(buffer.length, "size must be larger than 0"); | ||
| file_ = file; | ||
| chunk_ = buffer; | ||
|
|
@@ -2685,6 +2690,7 @@ See $(LREF byChunk) for an example. | |
| // the file mode on destruction, it is RefCounted on Windows. | ||
| struct BinaryWriterImpl(bool locking) | ||
| { | ||
| import std.traits : hasIndirections; | ||
| private: | ||
| FILE* fps; | ||
| string name; | ||
|
|
@@ -2830,10 +2836,11 @@ void main() | |
|
|
||
| unittest | ||
| { | ||
| import std.algorithm : copy, reverse; | ||
| import std.algorithm.mutation : reverse; | ||
| static import std.file; | ||
| import std.exception : collectException; | ||
| import std.range : only, retro, put; | ||
| import std.range : only, retro; | ||
| import std.range.primitives : put; | ||
| import std.string : format; | ||
|
|
||
| auto deleteme = testFilename(); | ||
|
|
@@ -3054,7 +3061,8 @@ unittest | |
| unittest | ||
| { | ||
| static import std.file; | ||
| import std.range; | ||
| import std.range : chain, only, repeat; | ||
| import std.range.primitives : isOutputRange; | ||
|
|
||
| auto deleteme = testFilename(); | ||
| scope(exit) std.file.remove(deleteme); | ||
|
|
@@ -3126,7 +3134,7 @@ struct LockingTextReader | |
|
|
||
| void opAssign(LockingTextReader r) | ||
| { | ||
| import std.algorithm : swap; | ||
| import std.algorithm.mutation : swap; | ||
| swap(this, r); | ||
| } | ||
|
|
||
|
|
@@ -3197,7 +3205,8 @@ unittest | |
| unittest // bugzilla 13686 | ||
| { | ||
| static import std.file; | ||
| import std.algorithm : equal; | ||
| import std.algorithm.comparison : equal; | ||
| import std.utf : byDchar; | ||
|
|
||
| auto deleteme = testFilename(); | ||
| std.file.write(deleteme, "Тест"); | ||
|
|
@@ -3207,7 +3216,6 @@ unittest // bugzilla 13686 | |
| File(deleteme).readf("%s", &s); | ||
| assert(s == "Тест"); | ||
|
|
||
| import std.utf; | ||
| auto ltr = LockingTextReader(File(deleteme)).byDchar; | ||
| assert(equal(ltr, "Тест".byDchar)); | ||
| } | ||
|
|
@@ -3324,6 +3332,7 @@ void writeln(T...)(T args) | |
| !isAggregateType!(typeof(args[0]))) | ||
| { | ||
| import std.exception : enforce; | ||
| import std.traits : isStaticArray; | ||
|
|
||
| // Specialization for strings - a very frequent case | ||
| auto w = .trustedStdout.lockingTextWriter(); | ||
|
|
@@ -4173,9 +4182,9 @@ en.cppreference.com/w/c/io#Narrow_and_wide_orientation, | |
| orientation). | ||
| */ | ||
| void toFile(T)(T data, string fileName) | ||
| if (is(typeof(std.algorithm.mutation.copy(data, stdout.lockingBinaryWriter)))) | ||
| if (is(typeof(copy(data, stdout.lockingBinaryWriter)))) | ||
| { | ||
| std.algorithm.mutation.copy(data, File(fileName, "wb").lockingBinaryWriter); | ||
| copy(data, File(fileName, "wb").lockingBinaryWriter); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made these two a module-level import up top, as the fact that this works without an explicit static import is actually a compiler bug that will soon be enforced. |
||
| } | ||
|
|
||
| unittest | ||
|
|
@@ -4317,8 +4326,6 @@ unittest | |
| // roll our own appender, but with "safe" arrays | ||
| private struct ReadlnAppender | ||
| { | ||
| import core.stdc.string; | ||
|
|
||
| char[] buf; | ||
| size_t pos; | ||
| bool safeAppend = false; | ||
|
|
@@ -4354,6 +4361,7 @@ private struct ReadlnAppender | |
| } | ||
| void reserve(size_t n) | ||
| { | ||
| import core.stdc.string : memcpy; | ||
| if (!reserveWithoutAllocating(n)) | ||
| { | ||
| size_t ncap = buf.length * 2 + 128 + n; | ||
|
|
@@ -4381,6 +4389,7 @@ private struct ReadlnAppender | |
| } | ||
| void putonly(char[] b) | ||
| { | ||
| import core.stdc.string : memcpy; | ||
| assert(pos == 0); // assume this is the only put call | ||
| if (reserveWithoutAllocating(b.length)) | ||
| memcpy(buf.ptr + pos, b.ptr, b.length); | ||
|
|
@@ -4692,13 +4701,14 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie | |
| } | ||
| else version (Posix) | ||
| { | ||
| import std.utf : encode; | ||
| buf.length = 0; | ||
| for (int c; (c = FGETWC(fp)) != -1; ) | ||
| { | ||
| if ((c & ~0x7F) == 0) | ||
| buf ~= cast(char)c; | ||
| else | ||
| std.utf.encode(buf, cast(dchar)c); | ||
| encode(buf, cast(dchar)c); | ||
| if (c == terminator) | ||
| break; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was being pulled in by a public import inside the import of
std.rangeabove, got rid of that import and made this explicit here.