add comments noting inefficiency of stream ops
authorSean Middleditch <sean@middleditch.us>
Sun, 17 Jan 2010 04:21:52 +0000 (20:21 -0800)
committerSean Middleditch <sean@middleditch.us>
Sun, 17 Jan 2010 04:21:52 +0000 (20:21 -0800)
janssonxx.h
janssonxx.tcc

index 15f34f7..260450f 100644 (file)
@@ -293,10 +293,10 @@ namespace jansson {
 
 } // namespace jansson
 
-// stream JSON value out
+// stream JSON value out -- inefficient and not recommended for production use
 inline std::ostream& operator<<(std::ostream& os, const jansson::Value& value);
 
-// read JSON value
+// read JSON value -- inefficient and not recommended for production use
 inline std::istream& operator>>(std::istream& is, jansson::Value& value);
 
 // include implementation code
index cdbadd8..74e4be5 100644 (file)
@@ -438,8 +438,10 @@ namespace jansson {
 
 // stream JSON value out
 std::ostream& operator<<(std::ostream& os, const jansson::Value& value) {
+       // get the temporary serialize string
        char* tmp = value.save_string();
        if (tmp != 0) {
+               // stream temp string out and release it
                os << tmp;
                free(tmp);
        }
@@ -448,9 +450,11 @@ std::ostream& operator<<(std::ostream& os, const jansson::Value& value) {
 
 // read JSON value
 std::istream& operator>>(std::istream& is, jansson::Value& value) {
+       // buffer the remaining bytes into a single string for Jansson
        std::stringstream tmp;
        while (is)
                tmp << static_cast<char>(is.get());
+       // parse the buffered string
        value = jansson::Value::load_string(tmp.str().c_str());
        return is;
 }