Remove cases where an array is used in a boolean context

This commit is contained in:
Daniel Murphy 2013-11-27 18:23:07 +11:00
parent 0d51ebd128
commit 13f343334c
8 changed files with 12 additions and 12 deletions

View file

@ -365,7 +365,7 @@ T enforce(T, Dg, string file = __FILE__, size_t line = __LINE__)
private void bailOut(string file, size_t line, in char[] msg) @safe pure private void bailOut(string file, size_t line, in char[] msg) @safe pure
{ {
throw new Exception(msg ? msg.idup : "Enforcement failed", file, line); throw new Exception(msg.ptr ? msg.idup : "Enforcement failed", file, line);
} }
unittest unittest

View file

@ -2233,7 +2233,7 @@ if (isInputRange!T)
formatValue(w, val.front, fmt); formatValue(w, val.front, fmt);
else else
formatElement(w, val.front, fmt); formatElement(w, val.front, fmt);
if (f.sep) if (f.sep.ptr)
{ {
put(w, fmt.trailing); put(w, fmt.trailing);
val.popFront(); val.popFront();

View file

@ -218,7 +218,7 @@ class MmFile
assert(0); assert(0);
} }
if (filename) if (filename.ptr)
{ {
auto namez = std.utf.toUTF16z(filename); auto namez = std.utf.toUTF16z(filename);
hFile = CreateFileW(namez, hFile = CreateFileW(namez,
@ -489,9 +489,9 @@ class MmFile
{ {
debug (MMFILE) printf("MmFile.unmap()\n"); debug (MMFILE) printf("MmFile.unmap()\n");
version(Windows) { version(Windows) {
errnoEnforce(!data || UnmapViewOfFile(data.ptr) != FALSE); errnoEnforce(!data.ptr || UnmapViewOfFile(data.ptr) != FALSE);
} else { } else {
errnoEnforce(!data || munmap(cast(void*)data, data.length) == 0, errnoEnforce(!data.ptr || munmap(cast(void*)data, data.length) == 0,
"munmap failed"); "munmap failed");
} }
data = null; data = null;

View file

@ -2931,7 +2931,7 @@ version (unittest)
int system(string command) int system(string command)
{ {
if (!command) return std.c.process.system(null); if (!command.ptr) return std.c.process.system(null);
const commandz = toStringz(command); const commandz = toStringz(command);
immutable status = std.c.process.system(commandz); immutable status = std.c.process.system(commandz);
if (status == -1) return status; if (status == -1) return status;

View file

@ -4273,7 +4273,7 @@ struct CtContext
{ {
$$ //$$ $$ //$$
} }
if(test_$$() >= 0)`, id, code ? code : "return 0;", if(test_$$() >= 0)`, id, code.ptr ? code : "return 0;",
ir[pc].mnemonic, id); ir[pc].mnemonic, id);
} }
} }

View file

@ -2712,7 +2712,7 @@ Initialize with a message and an error code. */
// If e is 0, we don't use the system error message. (The message // If e is 0, we don't use the system error message. (The message
// is "Success", which is rather pointless for an exception.) // is "Success", which is rather pointless for an exception.)
super(e == 0 ? message super(e == 0 ? message
: (message ? message ~ " (" ~ sysmsg ~ ")" : sysmsg)); : (message.ptr ? message ~ " (" ~ sysmsg ~ ")" : sysmsg));
} }
/** Convenience functions that throw an $(D StdioException). */ /** Convenience functions that throw an $(D StdioException). */

View file

@ -3387,11 +3387,11 @@ unittest
char[] soundex(const(char)[] string, char[] buffer = null) @safe pure nothrow char[] soundex(const(char)[] string, char[] buffer = null) @safe pure nothrow
in in
{ {
assert(!buffer || buffer.length >= 4); assert(!buffer.ptr || buffer.length >= 4);
} }
out (result) out (result)
{ {
if (result) if (result.ptr)
{ {
assert(result.length == 4); assert(result.length == 4);
assert(result[0] >= 'A' && result[0] <= 'Z'); assert(result[0] >= 'A' && result[0] <= 'Z');
@ -3422,7 +3422,7 @@ body
} }
if (b == 0) if (b == 0)
{ {
if (!buffer) if (!buffer.ptr)
buffer = new char[4]; buffer = new char[4];
buffer[0] = c; buffer[0] = c;
b++; b++;

View file

@ -377,7 +377,7 @@ S encode(S)(S s)
lastI = i + 1; lastI = i + 1;
} }
if (!result.data) return s; if (!result.data.ptr) return s;
result.put(s[lastI .. $]); result.put(s[lastI .. $]);
return result.data; return result.data;
} }