Skip to content

Commit

Permalink
more nothrow
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Apr 6, 2012
1 parent b13e568 commit 8fda49a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
83 changes: 49 additions & 34 deletions std/stream.d
Original file line number Diff line number Diff line change
Expand Up @@ -1299,31 +1299,38 @@ class Stream : InputStream, OutputStream {
override string toString() {
if (!readable)
return super.toString();
size_t pos;
size_t rdlen;
size_t blockSize;
char[] result;
if (seekable) {
ulong orig_pos = position;
position(0);
blockSize = cast(size_t)size;
result = new char[blockSize];
while (blockSize > 0) {
rdlen = readBlock(&result[pos], blockSize);
pos += rdlen;
blockSize -= rdlen;
}
position(orig_pos);
} else {
blockSize = 4096;
result = new char[blockSize];
while ((rdlen = readBlock(&result[pos], blockSize)) > 0) {
pos += rdlen;
blockSize += rdlen;
result.length = result.length + blockSize;
}
try
{
size_t pos;
size_t rdlen;
size_t blockSize;
char[] result;
if (seekable) {
ulong orig_pos = position;
scope(exit) position(orig_pos);
position(0);
blockSize = cast(size_t)size;
result = new char[blockSize];
while (blockSize > 0) {
rdlen = readBlock(&result[pos], blockSize);
pos += rdlen;
blockSize -= rdlen;
}
} else {
blockSize = 4096;
result = new char[blockSize];
while ((rdlen = readBlock(&result[pos], blockSize)) > 0) {
pos += rdlen;
blockSize += rdlen;
result.length = result.length + blockSize;
}
}
return cast(string) result[0 .. pos];
}
catch (Throwable)
{
return super.toString();
}
return cast(string) result[0 .. pos];
}

/***
Expand All @@ -1333,17 +1340,25 @@ class Stream : InputStream, OutputStream {
override size_t toHash() @trusted {
if (!readable || !seekable)
return super.toHash();
ulong pos = position;
uint crc = init_crc32 ();
position(0);
ulong len = size;
for (ulong i = 0; i < len; i++) {
ubyte c;
read(c);
crc = update_crc32(c, crc);
try
{
ulong pos = position;
scope(exit) position(pos);
uint crc = init_crc32();
position(0);
ulong len = size;
for (ulong i = 0; i < len; i++)
{
ubyte c;
read(c);
crc = update_crc32(c, crc);
}
return crc;
}
catch (Throwable)
{
return super.toHash();
}
position(pos);
return crc;
}

// helper for checking that the stream is readable
Expand Down
6 changes: 2 additions & 4 deletions std/xml.d
Original file line number Diff line number Diff line change
Expand Up @@ -1122,9 +1122,7 @@ class Tag
*/
override hash_t toHash()
{
hash_t hash = 0;
foreach(dchar c;name) hash = hash * 11 + c;
return hash;
return typeid(name).getHash(&name);
}

/**
Expand Down Expand Up @@ -2843,7 +2841,7 @@ private
s = s[1..$];
}

hash_t hash(string s,hash_t h=0) @trusted
hash_t hash(string s,hash_t h=0) @trusted nothrow
{
return typeid(s).getHash(&s) + h;
}
Expand Down

0 comments on commit 8fda49a

Please sign in to comment.