Skip to content

Commit e8e4c7a

Browse files
committed
Use !s.empty() instead of s != ""
The use of "" requires constructing a std::string or dstringt, and then a string comparison. empty() is just an integer comparison (both for std::string an dstringt).
1 parent b4139b5 commit e8e4c7a

39 files changed

+84
-91
lines changed

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ main_function_resultt get_main_symbol(
517517
messaget message(message_handler);
518518

519519
// find main symbol
520-
if(config.main!="")
520+
if(!config.main.empty())
521521
{
522522
// Add java:: prefix
523523
std::string main_identifier="java::"+config.main;

jbmc/unit/java-testing-utils/require_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ require_type::require_struct_tag(const typet &type, const irep_idt &identifier)
452452
{
453453
REQUIRE(type.id() == ID_struct_tag);
454454
const struct_tag_typet &result = to_struct_tag_type(type);
455-
if(identifier != "")
455+
if(!identifier.empty())
456456
{
457457
REQUIRE(result.get_identifier() == identifier);
458458
}

src/analyses/invariant_set.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ bool inv_object_storet::get(const exprt &expr, unsigned &n)
6464
unsigned inv_object_storet::add(const exprt &expr)
6565
{
6666
std::string s=build_string(expr);
67-
68-
assert(s!="");
67+
CHECK_RETURN(!s.empty());
6968

7069
mapt::number_type n=map.number(s);
7170

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool ansi_c_entry_point(
123123
irep_idt main_symbol;
124124

125125
// find main symbol
126-
if(config.main!="")
126+
if(!config.main.empty())
127127
{
128128
std::list<irep_idt> matches;
129129

src/ansi-c/expr2c.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ std::string expr2ct::convert_rec(
330330
std::string dest=q+"union";
331331

332332
const irep_idt &tag=union_type.get_tag();
333-
if(tag!="")
333+
if(!tag.empty())
334334
dest+=" "+id2string(tag);
335335

336336
if(!union_type.is_incomplete())
@@ -414,7 +414,7 @@ std::string expr2ct::convert_rec(
414414
// The star gets attached to the declarator.
415415
std::string new_declarator="*";
416416

417-
if(q != "" && (!declarator.empty() || subtype.id() == ID_pointer))
417+
if(!q.empty() && (!declarator.empty() || subtype.id() == ID_pointer))
418418
{
419419
new_declarator+=" "+q;
420420
}
@@ -442,7 +442,7 @@ std::string expr2ct::convert_rec(
442442

443443
// Providing we have a valid identifer, we can just use that rather than
444444
// trying to find the concrete type
445-
if(typedef_identifer!="")
445+
if(!typedef_identifer.empty())
446446
{
447447
return q+id2string(typedef_identifer)+d;
448448
}
@@ -454,7 +454,7 @@ std::string expr2ct::convert_rec(
454454
{
455455
std::string dest=q+"struct";
456456
const irep_idt &tag=to_struct_type(followed).get_tag();
457-
if(tag!="")
457+
if(!tag.empty())
458458
dest+=" "+id2string(tag);
459459
dest+=d;
460460
return dest;
@@ -463,7 +463,7 @@ std::string expr2ct::convert_rec(
463463
{
464464
std::string dest=q+"union";
465465
const irep_idt &tag=to_union_type(followed).get_tag();
466-
if(tag!="")
466+
if(!tag.empty())
467467
dest+=" "+id2string(tag);
468468
dest+=d;
469469
return dest;
@@ -479,7 +479,7 @@ std::string expr2ct::convert_rec(
479479

480480
std::string dest=q+"struct";
481481
const std::string &tag=ns.follow_tag(struct_tag_type).get_string(ID_tag);
482-
if(tag!="")
482+
if(!tag.empty())
483483
dest+=" "+tag;
484484
dest+=d;
485485

@@ -492,7 +492,7 @@ std::string expr2ct::convert_rec(
492492

493493
std::string dest=q+"union";
494494
const std::string &tag=ns.follow_tag(union_tag_type).get_string(ID_tag);
495-
if(tag!="")
495+
if(!tag.empty())
496496
dest+=" "+tag;
497497
dest+=d;
498498

@@ -672,7 +672,7 @@ std::string expr2ct::convert_struct_type(
672672
std::string dest=qualifiers+"struct";
673673

674674
const irep_idt &tag=struct_type.get_tag();
675-
if(tag!="")
675+
if(!tag.empty())
676676
dest+=" "+id2string(tag);
677677

678678
if(inc_struct_body && !struct_type.is_incomplete())
@@ -1565,7 +1565,7 @@ std::string expr2ct::convert_member(
15651565

15661566
irep_idt component_name=src.get_component_name();
15671567

1568-
if(component_name!="")
1568+
if(!component_name.empty())
15691569
{
15701570
const exprt &comp_expr = struct_union_type.get_component(component_name);
15711571

@@ -1873,7 +1873,7 @@ std::string expr2ct::convert_constant(
18731873
{
18741874
dest=ieee_floatt(to_constant_expr(src)).to_ansi_c_string();
18751875

1876-
if(dest!="" && isdigit(dest[dest.size()-1]))
1876+
if(!dest.empty() && isdigit(dest[dest.size() - 1]))
18771877
{
18781878
if(dest.find('.')==std::string::npos)
18791879
dest+=".0";
@@ -1902,7 +1902,7 @@ std::string expr2ct::convert_constant(
19021902
{
19031903
dest=fixedbvt(to_constant_expr(src)).to_ansi_c_string();
19041904

1905-
if(dest!="" && isdigit(dest[dest.size()-1]))
1905+
if(!dest.empty() && isdigit(dest[dest.size() - 1]))
19061906
{
19071907
if(src.type()==float_type())
19081908
dest+='f';

src/cbmc/bmc.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ safety_checkert::resultt bmct::execute(
139139
safety_checkert::resultt::ERROR:safety_checkert::resultt::SAFE;
140140
}
141141

142-
if(options.get_option("localize-faults")!="")
142+
if(!options.get_option("localize-faults").empty())
143143
{
144144
fault_localizationt fault_localization(
145145
goto_functions, *this, options);
@@ -241,8 +241,9 @@ safety_checkert::resultt bmct::stop_on_fail()
241241
return resultt::UNSAFE;
242242

243243
default:
244-
if(options.get_bool_option("dimacs") ||
245-
options.get_option("outfile")!="")
244+
if(
245+
options.get_bool_option("dimacs") ||
246+
!options.get_option("outfile").empty())
246247
return resultt::SAFE;
247248

248249
error() << "decision procedure failed" << eom;

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
218218
}
219219
}
220220

221-
// there is always a constructor for non-PODs
222-
assert(constructor_name!="");
221+
INVARIANT(!constructor_name.empty(), "non-PODs should have a constructor");
223222

224223
side_effect_expr_function_callt function_call(
225224
cpp_namet(constructor_name, source_location).as_expr(),

src/cpp/cpp_destructor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
9797
}
9898
}
9999

100-
// there is always a destructor for non-PODs
101-
assert(dtor_name!="");
100+
INVARIANT(!dtor_name.empty(), "non-PODs should have a destructor");
102101

103102
cpp_namet cpp_name(dtor_name, source_location);
104103

src/cpp/cpp_type2name.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ Author: Daniel Kroening, [email protected]
1919

2020
static std::string do_prefix(const std::string &s)
2121
{
22-
if(s.find(',')!=std::string::npos ||
23-
(s!="" && isdigit(s[0])))
22+
if(s.find(',') != std::string::npos || (!s.empty() && isdigit(s[0])))
2423
return std::to_string(s.size())+"_"+s;
2524

2625
return s;

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,7 @@ void cpp_typecheckt::typecheck_expr_member(
12051205
}
12061206

12071207
const irep_idt &component_name=expr.get(ID_component_name);
1208-
1209-
assert(component_name!="");
1208+
INVARIANT(!component_name.empty(), "component name should not be empty");
12101209

12111210
exprt component;
12121211
component.make_nil();
@@ -2146,7 +2145,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
21462145
// special case for the initialization of parents
21472146
if(member.get_bool(ID_C_not_accessible))
21482147
{
2149-
assert(member.get(ID_C_access)!="");
2148+
PRECONDITION(!member.get(ID_C_access).empty());
21502149
tmp_object_expr.set(ID_C_not_accessible, true);
21512150
tmp_object_expr.set(ID_C_access, member.get(ID_C_access));
21522151
}

0 commit comments

Comments
 (0)