Browse Source

cleanup:
- constify
- sync with style guidelines
- avoid unnecessary copies when we can use references


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1407 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 15 years ago
parent
commit
ad2c089bee
1 changed files with 108 additions and 171 deletions
  1. 108 171
      src/lib/cc/data.cc

+ 108 - 171
src/lib/cc/data.cc

@@ -59,8 +59,7 @@ std::ostream& operator <<(std::ostream &out, const isc::data::ElementPtr& e) {
     return out << e->str();
     return out << e->str();
 }
 }
 
 
-bool operator==(const isc::data::ElementPtr a, const isc::data::ElementPtr b)
+bool operator==(const isc::data::ElementPtr a, const isc::data::ElementPtr b) {
-{
     return a->equals(b);
     return a->equals(b);
 };
 };
 
 
@@ -68,8 +67,7 @@ bool operator==(const isc::data::ElementPtr a, const isc::data::ElementPtr b)
 // factory functions
 // factory functions
 //
 //
 ElementPtr
 ElementPtr
-Element::create(const int i)
+Element::create(const int i) {
-{
     try {
     try {
         return ElementPtr(new IntElement(i));
         return ElementPtr(new IntElement(i));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -78,8 +76,7 @@ Element::create(const int i)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::create(const double d)
+Element::create(const double d) {
-{
     try {
     try {
         return ElementPtr(new DoubleElement(d));
         return ElementPtr(new DoubleElement(d));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -88,8 +85,7 @@ Element::create(const double d)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::create(const std::string& s)
+Element::create(const std::string& s) {
-{
     try {
     try {
         return ElementPtr(new StringElement(s));
         return ElementPtr(new StringElement(s));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -98,8 +94,7 @@ Element::create(const std::string& s)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::create(const bool b)
+Element::create(const bool b) {
-{
     try {
     try {
         return ElementPtr(new BoolElement(b));
         return ElementPtr(new BoolElement(b));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -108,8 +103,7 @@ Element::create(const bool b)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::create(const std::vector<ElementPtr>& v)
+Element::create(const std::vector<ElementPtr>& v) {
-{
     try {
     try {
         return ElementPtr(new ListElement(v));
         return ElementPtr(new ListElement(v));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -118,8 +112,7 @@ Element::create(const std::vector<ElementPtr>& v)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::create(const std::map<std::string, ElementPtr>& m)
+Element::create(const std::map<std::string, ElementPtr>& m) {
-{
     try {
     try {
         return ElementPtr(new MapElement(m));
         return ElementPtr(new MapElement(m));
     } catch (std::bad_alloc) {
     } catch (std::bad_alloc) {
@@ -133,9 +126,8 @@ Element::create(const std::map<std::string, ElementPtr>& m)
 //
 //
 
 
 static bool
 static bool
-char_in(char c, const char *chars)
+char_in(const char c, const char *chars) {
-{
+    for (size_t i = 0; i < strlen(chars); ++i) {
-    for (size_t i = 0; i < strlen(chars); i++) {
         if (chars[i] == c) {
         if (chars[i] == c) {
             return true;
             return true;
         }
         }
@@ -144,15 +136,14 @@ char_in(char c, const char *chars)
 }
 }
 
 
 static void
 static void
-skip_chars(std::istream &in, const char *chars, int& line, int& pos)
+skip_chars(std::istream &in, const char *chars, int& line, int& pos) {
-{
     char c = in.peek();
     char c = in.peek();
     while (char_in(c, chars) && c != EOF) {
     while (char_in(c, chars) && c != EOF) {
         if (c == '\n') {
         if (c == '\n') {
-            line++;
+            ++line;
             pos = 1;
             pos = 1;
         } else {
         } else {
-            pos++;
+            ++pos;
         }
         }
         in.get();
         in.get();
         c = in.peek();
         c = in.peek();
@@ -169,26 +160,26 @@ skip_to(std::istream &in, const std::string& file, int& line,
         int& pos, const char* chars, const char* may_skip="")
         int& pos, const char* chars, const char* may_skip="")
 {
 {
     char c = in.get();
     char c = in.get();
-    pos++;
+    ++pos;
     while (c != EOF) {
     while (c != EOF) {
         if (c == '\n') {
         if (c == '\n') {
             pos = 1;
             pos = 1;
-            line++;
+            ++line;
         }
         }
         if (char_in(c, may_skip)) {
         if (char_in(c, may_skip)) {
             c = in.get();
             c = in.get();
-            pos++;
+            ++pos;
         } else if (char_in(c, chars)) {
         } else if (char_in(c, chars)) {
             while(char_in(in.peek(), may_skip)) {
             while(char_in(in.peek(), may_skip)) {
                 if (in.peek() == '\n') {
                 if (in.peek() == '\n') {
                     pos = 1;
                     pos = 1;
-                    line++;
+                    ++line;
                 }
                 }
                 in.get();
                 in.get();
-                pos++;
+                ++pos;
             }
             }
             in.putback(c);
             in.putback(c);
-            pos--;
+            --pos;
             return;
             return;
         } else {
         } else {
             throwParseError(std::string("'") + c + "' read, one of \"" + chars + "\" expected", file, line, pos);
             throwParseError(std::string("'") + c + "' read, one of \"" + chars + "\" expected", file, line, pos);
@@ -203,10 +194,10 @@ str_from_stringstream(std::istream &in, const std::string& file, int& line, int&
     char c = 0;
     char c = 0;
     std::stringstream ss;
     std::stringstream ss;
     c = in.get();
     c = in.get();
-    pos++;
+    ++pos;
     if (c == '"') {
     if (c == '"') {
         c = in.get();
         c = in.get();
-        pos++;
+        ++pos;
     } else {
     } else {
         throwParseError("String expected", file, line, pos);
         throwParseError("String expected", file, line, pos);
     }
     }
@@ -214,17 +205,16 @@ str_from_stringstream(std::istream &in, const std::string& file, int& line, int&
         ss << c;
         ss << c;
         if (c == '\\' && in.peek() == '"') {
         if (c == '\\' && in.peek() == '"') {
             ss << in.get();
             ss << in.get();
-            pos++;
+            ++pos;
         }
         }
         c = in.get();
         c = in.get();
-        pos++;
+        ++pos;
     }
     }
     return ss.str();
     return ss.str();
 }
 }
 
 
 static std::string
 static std::string
-word_from_stringstream(std::istream &in, int& line, int& pos)
+word_from_stringstream(std::istream &in, int& line, int& pos) {
-{
     std::stringstream ss;
     std::stringstream ss;
     while (isalpha(in.peek())) {
     while (isalpha(in.peek())) {
         ss << (char) in.get();
         ss << (char) in.get();
@@ -234,30 +224,27 @@ word_from_stringstream(std::istream &in, int& line, int& pos)
 }
 }
 
 
 static inline int
 static inline int
-count_chars_i(int i)
+count_chars_i(int i) {
-{
     int result = 1;
     int result = 1;
     while (i > 10) {
     while (i > 10) {
-        result++;
+        ++result;
-        i=i/10;
+        i = i / 10;
     }
     }
     return result;
     return result;
 }
 }
 
 
 static inline int
 static inline int
-count_chars_d(double d)
+count_chars_d(double d) {
-{
     int result = 1;
     int result = 1;
-    while(d < 1.0) {
+    while (d < 1.0) {
-        result++;
+        ++result;
         d = d * 10;
         d = d * 10;
     }
     }
     return result;
     return result;
 }
 }
 
 
 static ElementPtr
 static ElementPtr
-from_stringstream_int_or_double(std::istream &in, int &line, int &pos)
+from_stringstream_int_or_double(std::istream &in, int &line, int &pos) {
-{
     int i;
     int i;
     in >> i;
     in >> i;
     pos += count_chars_i(i);
     pos += count_chars_i(i);
@@ -275,7 +262,7 @@ from_stringstream_int_or_double(std::istream &in, int &line, int &pos)
 static ElementPtr
 static ElementPtr
 from_stringstream_bool(std::istream &in, const std::string& file, int& line, int& pos)
 from_stringstream_bool(std::istream &in, const std::string& file, int& line, int& pos)
 {
 {
-    std::string word = word_from_stringstream(in, line, pos);
+    const std::string word = word_from_stringstream(in, line, pos);
     if (boost::iequals(word, "True")) {
     if (boost::iequals(word, "True")) {
         return Element::create(true);
         return Element::create(true);
     } else if (boost::iequals(word, "False")) {
     } else if (boost::iequals(word, "False")) {
@@ -288,7 +275,7 @@ from_stringstream_bool(std::istream &in, const std::string& file, int& line, int
 }
 }
 
 
 static ElementPtr
 static ElementPtr
-from_stringstream_string(std::istream &in, const std::string& file, int& line, int& pos)
+from_stringstream_string(std::istream& in, const std::string& file, int& line, int& pos)
 {
 {
     return Element::create(str_from_stringstream(in, file, line, pos));
     return Element::create(str_from_stringstream(in, file, line, pos));
 }
 }
@@ -344,14 +331,13 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, int&
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::createFromString(std::istream &in) throw(ParseError)
+Element::createFromString(std::istream& in) throw(ParseError) {
-{
     int line = 1, pos = 1;
     int line = 1, pos = 1;
     return createFromString(in, "<istream>", line, pos);
     return createFromString(in, "<istream>", line, pos);
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::createFromString(std::istream &in, const std::string& file_name) throw(ParseError)
+Element::createFromString(std::istream& in, const std::string& file_name) throw(ParseError)
 {
 {
     int line = 1, pos = 1;
     int line = 1, pos = 1;
     return createFromString(in, file_name, line, pos);
     return createFromString(in, file_name, line, pos);
@@ -418,8 +404,7 @@ Element::createFromString(std::istream &in, const std::string& file, int& line,
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::createFromString(const std::string &in)
+Element::createFromString(const std::string &in) {
-{
     std::stringstream ss;
     std::stringstream ss;
     ss << in;
     ss << in;
     return createFromString(ss, "<string>");
     return createFromString(ss, "<string>");
@@ -429,24 +414,21 @@ Element::createFromString(const std::string &in)
 // a general to_str() function
 // a general to_str() function
 //
 //
 std::string
 std::string
-IntElement::str()
+IntElement::str() {
-{
     std::stringstream ss;
     std::stringstream ss;
     ss << intValue();
     ss << intValue();
     return ss.str();
     return ss.str();
 }
 }
 
 
 std::string
 std::string
-DoubleElement::str()
+DoubleElement::str() {
-{
     std::stringstream ss;
     std::stringstream ss;
     ss << doubleValue();
     ss << doubleValue();
     return ss.str();
     return ss.str();
 }
 }
 
 
 std::string
 std::string
-BoolElement::str()
+BoolElement::str() {
-{
     if (b) {
     if (b) {
         return "True";
         return "True";
     } else {
     } else {
@@ -455,8 +437,7 @@ BoolElement::str()
 }
 }
 
 
 std::string
 std::string
-StringElement::str()
+StringElement::str() {
-{
     std::stringstream ss;
     std::stringstream ss;
     ss << "\"";
     ss << "\"";
     ss << stringValue();
     ss << stringValue();
@@ -465,13 +446,13 @@ StringElement::str()
 }
 }
 
 
 std::string
 std::string
-ListElement::str()
+ListElement::str() {
-{
     std::stringstream ss;
     std::stringstream ss;
-    std::vector<ElementPtr> v;
     ss << "[ ";
     ss << "[ ";
-    v = listValue();
+
-    for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) {
+    const std::vector<ElementPtr>& v = listValue();
+    for (std::vector<ElementPtr>::const_iterator it = v.begin();
+         it != v.end(); ++it) {
         if (it != v.begin()) {
         if (it != v.begin()) {
             ss << ", ";
             ss << ", ";
         }
         }
@@ -482,13 +463,13 @@ ListElement::str()
 }
 }
 
 
 std::string
 std::string
-MapElement::str()
+MapElement::str() {
-{
     std::stringstream ss;
     std::stringstream ss;
-    std::map<std::string, ElementPtr> m;
     ss << "{";
     ss << "{";
-    m = mapValue();
+
-    for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) {
+    const std::map<std::string, ElementPtr>& m = mapValue();
+    for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
+         it != m.end(); ++it) {
         if (it != m.begin()) {
         if (it != m.begin()) {
             ss << ", ";
             ss << ", ";
         }
         }
@@ -508,17 +489,16 @@ MapElement::str()
 // returns 0 if it could simply not be found
 // returns 0 if it could simply not be found
 // should that also be an exception?
 // should that also be an exception?
 ElementPtr
 ElementPtr
-MapElement::find(const std::string& id)
+MapElement::find(const std::string& id) {
-{
+    const size_t sep = id.find('/');
-    size_t sep = id.find('/');
     if (sep == std::string::npos) {
     if (sep == std::string::npos) {
         return get(id);
         return get(id);
     } else {
     } else {
         ElementPtr ce = get(id.substr(0, sep));
         ElementPtr ce = get(id.substr(0, sep));
         if (ce) {
         if (ce) {
             // ignore trailing slash
             // ignore trailing slash
-            if  (sep+1 != id.size()) {
+            if  (sep + 1 != id.size()) {
-                return ce->find(id.substr(sep+1));
+                return ce->find(id.substr(sep + 1));
             } else {
             } else {
                 return ce;
                 return ce;
             }
             }
@@ -535,9 +515,8 @@ MapElement::find(const std::string& id)
 ElementPtr decode_element(std::stringstream& in, int& in_length);
 ElementPtr decode_element(std::stringstream& in, int& in_length);
 
 
 static unsigned char
 static unsigned char
-get_byte(std::stringstream& in)
+get_byte(std::stringstream& in) {
-{
+    const int c = in.get();
-    int c = in.get();
     if (c == EOF) {
     if (c == EOF) {
         throw DecodeError("End of data while decoding wire format message");
         throw DecodeError("End of data while decoding wire format message");
     }
     }
@@ -546,11 +525,10 @@ get_byte(std::stringstream& in)
 }
 }
 
 
 std::string
 std::string
-decode_tag(std::stringstream& in, int& item_length)
+decode_tag(std::stringstream& in, int& item_length) {
-{
     char buf[256];
     char buf[256];
 
 
-    int len = get_byte(in);
+    const int len = get_byte(in);
     item_length--;
     item_length--;
 
 
     in.read(buf, len);
     in.read(buf, len);
@@ -564,10 +542,8 @@ decode_tag(std::stringstream& in, int& item_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_bool(std::stringstream& in, int& item_length)
+decode_bool(std::stringstream& in, int& item_length) {
-{
+    const char c = in.get();
-    char c;
-    c = in.get();
     
     
     if (c == '1') {
     if (c == '1') {
         return Element::create(true);
         return Element::create(true);
@@ -577,22 +553,19 @@ decode_bool(std::stringstream& in, int& item_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_int(std::stringstream& in, int& item_length)
+decode_int(std::stringstream& in, int& item_length) {
-{
     int skip, me;
     int skip, me;
     return from_stringstream_int_or_double(in, skip, me);
     return from_stringstream_int_or_double(in, skip, me);
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_real(std::stringstream& in, int& item_length)
+decode_real(std::stringstream& in, int& item_length) {
-{
     int skip, me;
     int skip, me;
     return from_stringstream_int_or_double(in, skip, me);
     return from_stringstream_int_or_double(in, skip, me);
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_blob(std::stringstream& in, int& item_length)
+decode_blob(std::stringstream& in, int& item_length) {
-{
     char *buf = new char[item_length + 1];
     char *buf = new char[item_length + 1];
 
 
     in.read(buf, item_length);
     in.read(buf, item_length);
@@ -611,8 +584,7 @@ decode_blob(std::stringstream& in, int& item_length)
 
 
 // XXXMLG currently identical to decode_blob
 // XXXMLG currently identical to decode_blob
 ElementPtr
 ElementPtr
-decode_utf8(std::stringstream& in, int& item_length)
+decode_utf8(std::stringstream& in, int& item_length) {
-{
     char *buf = new char[item_length + 1];
     char *buf = new char[item_length + 1];
 
 
     in.read(buf, item_length);
     in.read(buf, item_length);
@@ -630,8 +602,7 @@ decode_utf8(std::stringstream& in, int& item_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_hash(std::stringstream& in, int& item_length)
+decode_hash(std::stringstream& in, int& item_length) {
-{
     std::map<std::string, ElementPtr> m;
     std::map<std::string, ElementPtr> m;
     std::pair<std::string, ElementPtr> p;
     std::pair<std::string, ElementPtr> p;
 
 
@@ -645,8 +616,7 @@ decode_hash(std::stringstream& in, int& item_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_list(std::stringstream& in, int& item_length)
+decode_list(std::stringstream& in, int& item_length) {
-{
     std::vector<ElementPtr> v;
     std::vector<ElementPtr> v;
 
 
     while (item_length > 0) {
     while (item_length > 0) {
@@ -656,19 +626,17 @@ decode_list(std::stringstream& in, int& item_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_null(std::stringstream& in, int& item_length)
+decode_null(std::stringstream& in, int& item_length) {
-{
     return Element::create("NULL");
     return Element::create("NULL");
 }
 }
 
 
 ElementPtr
 ElementPtr
-decode_element(std::stringstream& in, int& in_length)
+decode_element(std::stringstream& in, int& in_length) {
-{
     ElementPtr element;
     ElementPtr element;
 
 
-    unsigned char type_and_length = get_byte(in);
+    const unsigned char type_and_length = get_byte(in);
-    unsigned char type = type_and_length & ITEM_MASK;
+    const unsigned char type = type_and_length & ITEM_MASK;
-    unsigned char lenbytes = type_and_length & ITEM_LENGTH_MASK;
+    const unsigned char lenbytes = type_and_length & ITEM_LENGTH_MASK;
     in_length--;
     in_length--;
 
 
     int item_length = 0;
     int item_length = 0;
@@ -721,30 +689,26 @@ decode_element(std::stringstream& in, int& in_length)
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::fromWire(const std::string& s)
+Element::fromWire(const std::string& s) {
-{
     std::stringstream ss;
     std::stringstream ss;
     ss << s;
     ss << s;
     return fromWire(ss, s.length());
     return fromWire(ss, s.length());
 }
 }
 
 
 ElementPtr
 ElementPtr
-Element::fromWire(std::stringstream& in, int length)
+Element::fromWire(std::stringstream& in, int length) {
-{
     //
     //
     // Check protocol version
     // Check protocol version
     //
     //
-    for (int i = 0 ; i < 4 ; i++) {
+    for (int i = 0 ; i < 4 ; ++i) {
-        unsigned char version_byte = get_byte(in);
+        const unsigned char version_byte = get_byte(in);
         if (PROTOCOL_VERSION[i] != version_byte) {
         if (PROTOCOL_VERSION[i] != version_byte) {
             throw DecodeError("Protocol version incorrect");
             throw DecodeError("Protocol version incorrect");
         }
         }
     }
     }
     length -= 4;
     length -= 4;
 
 
-    ElementPtr element;
+    return (decode_hash(in, length));
-    element = decode_hash(in, length);
-    return (element);
 }
 }
 
 
 //
 //
@@ -752,12 +716,11 @@ Element::fromWire(std::stringstream& in, int length)
 //
 //
 
 
 std::string
 std::string
-encode_length(unsigned int length, unsigned char type)
+encode_length(const unsigned int length, unsigned char type) {
-{
     std::stringstream ss;
     std::stringstream ss;
 
 
     if (length <= 0x000000ff) {
     if (length <= 0x000000ff) {
-        unsigned char val = (length & 0x000000ff);
+        const unsigned char val = (length & 0x000000ff);
         type |= ITEM_LENGTH_8;
         type |= ITEM_LENGTH_8;
         ss << type << val;
         ss << type << val;
     } else if (length <= 0x0000ffff) {
     } else if (length <= 0x0000ffff) {
@@ -779,38 +742,27 @@ encode_length(unsigned int length, unsigned char type)
 }
 }
 
 
 std::string
 std::string
-Element::toWire(int omit_length)
+Element::toWire(const int omit_length) {
-{
     std::stringstream ss;
     std::stringstream ss;
     toWire(ss, omit_length);
     toWire(ss, omit_length);
     return ss.str();
     return ss.str();
 }
 }
 
 
 void
 void
-StringElement::toWire(std::stringstream& ss, int omit_length)
+StringElement::toWire(std::stringstream& ss, const int omit_length) {
-{
     unsigned int length = stringValue().length();
     unsigned int length = stringValue().length();
     ss << encode_length(length, ITEM_UTF8) << stringValue();
     ss << encode_length(length, ITEM_UTF8) << stringValue();
 }
 }
 
 
 void
 void
-IntElement::toWire(std::stringstream& ss, int omit_length)
+IntElement::toWire(std::stringstream& ss, const int omit_length) {
-{
+    const std::string& s = str();
-    std::stringstream text;
+    ss << encode_length(s.length(), ITEM_INT) << s;
-
-    text << str();
-    int length = text.str().length();
-    ss << encode_length(length, ITEM_INT) << text.str();
 }
 }
 
 
 void
 void
-BoolElement::toWire(std::stringstream& ss, int omit_length)
+BoolElement::toWire(std::stringstream& ss, const int omit_length) {
-{
+    ss << encode_length(1, ITEM_BOOL);
-    std::stringstream text;
-
-    text << str();
-    int length = 1;
-    ss << encode_length(length, ITEM_BOOL);
     if (boolValue()) {
     if (boolValue()) {
         ss << 0x01;
         ss << 0x01;
     } else {
     } else {
@@ -819,22 +771,19 @@ BoolElement::toWire(std::stringstream& ss, int omit_length)
 }
 }
 
 
 void
 void
-DoubleElement::toWire(std::stringstream& ss, int omit_length)
+DoubleElement::toWire(std::stringstream& ss, const int omit_length) {
-{
     std::stringstream text;
     std::stringstream text;
 
 
     text << str();
     text << str();
-    int length = text.str().length();
+    const int length = text.str().length();
     ss << encode_length(length, ITEM_REAL) << text.str();
     ss << encode_length(length, ITEM_REAL) << text.str();
 }
 }
 
 
 void
 void
-ListElement::toWire(std::stringstream& ss, int omit_length)
+ListElement::toWire(std::stringstream& ss, const int omit_length) {
-{
     std::stringstream ss2;
     std::stringstream ss2;
-    std::vector<ElementPtr> v;
+    const std::vector<ElementPtr>& v = listValue();
-    v = listValue();
+    for (std::vector<ElementPtr>::const_iterator it = v.begin() ;
-    for (std::vector<ElementPtr>::iterator it = v.begin() ;
          it != v.end() ; ++it) {
          it != v.end() ; ++it) {
         (*it)->toWire(ss2, 0);
         (*it)->toWire(ss2, 0);
     }
     }
@@ -857,17 +806,14 @@ ListElement::toWire(std::stringstream& ss, int omit_length)
 }
 }
 
 
 void
 void
-encode_tag(std::stringstream& ss, const std::string &s)
+encode_tag(std::stringstream& ss, const std::string &s) {
-{
+    const unsigned char val = s.length() & 0x000000ff;
-    int length = s.length();
-    unsigned char val = length & 0x000000ff;
 
 
     ss << val << s;
     ss << val << s;
 }
 }
 
 
 void
 void
-MapElement::toWire(std::stringstream& ss, int omit_length)
+MapElement::toWire(std::stringstream& ss, int omit_length) {
-{
     std::stringstream ss2;
     std::stringstream ss2;
 
 
     //
     //
@@ -912,49 +858,44 @@ MapElement::find(const std::string& id, ElementPtr& t) {
             t = p;
             t = p;
             return true;
             return true;
         }
         }
-    } catch (TypeError e) {
+    } catch (const TypeError& e) {
         // ignore
         // ignore
     }
     }
     return false;
     return false;
 }
 }
 
 
 bool
 bool
-IntElement::equals(ElementPtr other)
+IntElement::equals(ElementPtr other) {
-{
     return (other->getType() == Element::integer) &&
     return (other->getType() == Element::integer) &&
            (i == other->intValue());
            (i == other->intValue());
 }
 }
 
 
 bool
 bool
-DoubleElement::equals(ElementPtr other)
+DoubleElement::equals(ElementPtr other) {
-{
     return (other->getType() == Element::real) &&
     return (other->getType() == Element::real) &&
            (d == other->doubleValue());
            (d == other->doubleValue());
 }
 }
 
 
 bool
 bool
-BoolElement::equals(ElementPtr other)
+BoolElement::equals(ElementPtr other) {
-{
     return (other->getType() == Element::boolean) &&
     return (other->getType() == Element::boolean) &&
            (b == other->boolValue());
            (b == other->boolValue());
 }
 }
 
 
 bool
 bool
-StringElement::equals(ElementPtr other)
+StringElement::equals(ElementPtr other) {
-{
     return (other->getType() == Element::string) &&
     return (other->getType() == Element::string) &&
            (s == other->stringValue());
            (s == other->stringValue());
 }
 }
 
 
 bool
 bool
-ListElement::equals(ElementPtr other)
+ListElement::equals(ElementPtr other) {
-{
     if (other->getType() == Element::list) {
     if (other->getType() == Element::list) {
-        int s = size();
+        const int s = size();
         if (s != other->size()) {
         if (s != other->size()) {
             return false;
             return false;
         }
         }
-        for (int i = 0; i < s; i++) {
+        for (int i = 0; i < s; ++i) {
             if (!get(i)->equals(other->get(i))) {
             if (!get(i)->equals(other->get(i))) {
                 return false;
                 return false;
             }
             }
@@ -966,11 +907,10 @@ ListElement::equals(ElementPtr other)
 }
 }
 
 
 bool
 bool
-MapElement::equals(ElementPtr other)
+MapElement::equals(ElementPtr other) {
-{
     if (other->getType() == Element::map) {
     if (other->getType() == Element::map) {
         std::map<std::string, ElementPtr> m = mapValue();
         std::map<std::string, ElementPtr> m = mapValue();
-        for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
+        for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
              it != m.end() ; ++it) {
              it != m.end() ; ++it) {
             if (other->contains((*it).first)) {
             if (other->contains((*it).first)) {
                 if (!get((*it).first)->equals(other->get((*it).first))) {
                 if (!get((*it).first)->equals(other->get((*it).first))) {
@@ -986,7 +926,7 @@ MapElement::equals(ElementPtr other)
         // differ (and if it's not missing the loop above has checked
         // differ (and if it's not missing the loop above has checked
         // it)
         // it)
         m = other->mapValue();
         m = other->mapValue();
-        for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
+        for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
              it != m.end() ; ++it) {
              it != m.end() ; ++it) {
             if (!contains((*it).first)) {
             if (!contains((*it).first)) {
                 return false;
                 return false;
@@ -999,14 +939,12 @@ MapElement::equals(ElementPtr other)
 }
 }
 
 
 bool
 bool
-isc::data::isNull(ElementPtr p)
+isc::data::isNull(ElementPtr p) {
-{
     return !p;
     return !p;
 }
 }
 
 
 void
 void
-isc::data::removeIdentical(ElementPtr a, const ElementPtr b)
+isc::data::removeIdentical(ElementPtr a, const ElementPtr b) {
-{
     if (!b) {
     if (!b) {
         return;
         return;
     }
     }
@@ -1015,7 +953,7 @@ isc::data::removeIdentical(ElementPtr a, const ElementPtr b)
     }
     }
 
 
     std::map<std::string, ElementPtr> m = a->mapValue();
     std::map<std::string, ElementPtr> m = a->mapValue();
-    for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
+    for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
          it != m.end() ; ++it) {
          it != m.end() ; ++it) {
         if (b->contains((*it).first)) {
         if (b->contains((*it).first)) {
             if (a->get((*it).first)->equals(b->get((*it).first))) {
             if (a->get((*it).first)->equals(b->get((*it).first))) {
@@ -1026,15 +964,14 @@ isc::data::removeIdentical(ElementPtr a, const ElementPtr b)
 }
 }
 
 
 void
 void
-isc::data::merge(ElementPtr element, const ElementPtr other)
+isc::data::merge(ElementPtr element, const ElementPtr other) {
-{
     if (element->getType() != Element::map ||
     if (element->getType() != Element::map ||
         other->getType() != Element::map) {
         other->getType() != Element::map) {
         isc_throw(TypeError, "merge arguments not MapElements");
         isc_throw(TypeError, "merge arguments not MapElements");
     }
     }
     
     
     std::map<std::string, ElementPtr> m = other->mapValue();
     std::map<std::string, ElementPtr> m = other->mapValue();
-    for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
+    for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
          it != m.end() ; ++it) {
          it != m.end() ; ++it) {
         if ((*it).second) {
         if ((*it).second) {
             element->set((*it).first, (*it).second);
             element->set((*it).first, (*it).second);