summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-14 12:22:18 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-14 12:22:18 +0900
commit2a76532fe845ea0934cec8999ad130ada7778c2a (patch)
tree842919c9145a2838a7155d8d4c3c87b581c0cdd6
parent636addd645a430c3b014ca99b11c1ee82b078a8b (diff)
parent7a8ed0fa3a46eb0716345eefe1408c80e4443210 (diff)
downloadmruby-2a76532fe845ea0934cec8999ad130ada7778c2a.tar.gz
mruby-2a76532fe845ea0934cec8999ad130ada7778c2a.zip
Merge pull request #2060 from cremno/exc_inspect-dup-file
exc_inspect: dup file and check mesg only once
-rw-r--r--src/error.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/error.c b/src/error.c
index c344509b9..64851bb56 100644
--- a/src/error.c
+++ b/src/error.c
@@ -122,28 +122,30 @@ static mrb_value
exc_inspect(mrb_state *mrb, mrb_value exc)
{
mrb_value str, mesg, file, line;
+ mrb_bool append_mesg;
mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
line = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "line"));
+ append_mesg = !mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0;
if (!mrb_nil_p(file) && !mrb_nil_p(line)) {
- str = file;
+ str = mrb_str_dup(mrb, file);
mrb_str_cat_lit(mrb, str, ":");
mrb_str_append(mrb, str, line);
mrb_str_cat_lit(mrb, str, ": ");
- if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
+ if (append_mesg) {
mrb_str_append(mrb, str, mesg);
mrb_str_cat_lit(mrb, str, " (");
}
mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc));
- if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
+ if (append_mesg) {
mrb_str_cat_lit(mrb, str, ")");
}
}
else {
str = mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc));
- if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
+ if (append_mesg) {
mrb_str_cat_lit(mrb, str, ": ");
mrb_str_append(mrb, str, mesg);
}