Removed Node.getToVar as it turned out to be a premature

optimization.
This commit is contained in:
Ferdinand Majerech 2011-10-29 22:53:46 +02:00
parent c385a3ae4d
commit b3a51800f7
3 changed files with 15 additions and 46 deletions

Binary file not shown.

View file

@ -336,20 +336,6 @@
<b>Throws:</b><div class="pbr">NodeException if unable to convert to specified type, or if
the value is out of range of requested type.</div>
</dd>
<dt class="d_decl">void <a name="getToVar"></a><span class="ddoc_psymbol">getToVar</span>(T)(out T <b>target</b>);
</dt>
<dd><p>Write the value of the node to target.
</p>
<p>If the target type does not match node type,
conversion is attempted.
</p>
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>target</td>
<td valign=top>Variable to write to.</td></tr>
</table></div>
<b>Throws:</b><div class="pbr">NodeException if unable to convert to specified type.</div>
</dd>
<dt class="d_decl">@property size_t <a name="length"></a><span class="ddoc_psymbol">length</span>();
</dt>

View file

@ -512,28 +512,10 @@ struct Node
* the value is out of range of requested type.
*/
@property T get(T)() if(!is(T == const))
{
T result;
getToVar!T(result);
return result;
}
/**
* Write the value of the node to target.
*
* If the target type does not match node type,
* conversion is attempted.
*
* Params: target = Variable to write to.
*
* Throws: NodeException if unable to convert to specified type.
*/
void getToVar(T)(out T target) if(!is(T == const))
{
if(isType!T)
{
target = value_.get!T;
return;
return value_.get!T;
}
static if(!Value.allowed!T)
@ -544,8 +526,7 @@ struct Node
auto object = as!YAMLObject;
if(object.type is typeid(T))
{
target = (cast(YAMLContainer!T)object).value_;
return;
return (cast(YAMLContainer!T)object).value_;
}
}
}
@ -554,8 +535,7 @@ struct Node
//we're getting the default value.
if(isMapping)
{
target = this["="].as!T;
return;
return this["="].as!T;
}
void throwUnexpectedType()
@ -570,8 +550,7 @@ struct Node
//Try to convert to string.
try
{
target = value_.coerce!T();
return;
return value_.coerce!T();
}
catch(VariantException e)
{
@ -583,37 +562,41 @@ struct Node
///Can convert int to float.
if(isInt())
{
target = to!T(value_.get!long);
return;
return to!T(value_.get!long);
}
else if(isFloat())
{
target = to!T(value_.get!real);
return;
return to!T(value_.get!real);
}
else
{
throwUnexpectedType();
assert(false);
}
}
else static if(isIntegral!T)
{
if(isInt())
{
long temp = value_.get!long;
const temp = value_.get!long;
if(temp < T.min || temp > T.max)
{
throw new Error("Integer value out of range of type " ~
typeid(T).toString ~ "Value: " ~ to!string(temp),
startMark_);
}
target = to!T(temp);
return;
return to!T(temp);
}
else
{
throwUnexpectedType();
assert(false);
}
}
else
{
throwUnexpectedType();
assert(false);
}
}