Reviewers: Mads Ager,

Description:
Refactoring using TempAssign.

Please review this at http://codereview.chromium.org/14147

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/serialize.cc
   M     src/utils.h


Index: src/utils.h
===================================================================
--- src/utils.h (revision 977)
+++ src/utils.h (working copy)
@@ -377,12 +377,14 @@
  template <typename T>
  class TempAssign {
   public:
-  TempAssign(T* var, T value): var_(var), old_value_(*var) {
+  TempAssign(T* var, const T& value): var_(var), old_value_(*var) {
      *var = value;
    }

    ~TempAssign() { *var_ = old_value_; }

+  const T& old_value() const { return old_value_; };
+
   private:
    T* var_;
    T old_value_;
Index: src/serialize.cc
===================================================================
--- src/serialize.cc    (revision 977)
+++ src/serialize.cc    (working copy)
@@ -933,19 +933,17 @@
  // Serialize objects by writing them into the stream.

  void Serializer::VisitPointers(Object** start, Object** end) {
-  bool root = root_;
-  root_ = false;
+  TempAssign<bool> temp_root(&root_, false);
    for (Object** p = start; p < end; ++p) {
      bool serialized;
      Address a = Encode(*p, &serialized);
-    if (root) {
+    if (temp_root.old_value()) {
        roots_++;
        // If the object was not just serialized,
        // write its encoded address instead.
        if (!serialized) PutEncodedAddress(a);
      }
    }
-  root_ = root;
  }


@@ -1236,10 +1234,9 @@


  void Deserializer::VisitPointers(Object** start, Object** end) {
-  bool root = root_;
-  root_ = false;
+  TempAssign<bool> temp_root(&root_, false);
    for (Object** p = start; p < end; ++p) {
-    if (root) {
+    if (temp_root.old_value()) {
        roots_++;
        // Read the next object or pointer from the stream
        // pointer in the stream.
@@ -1256,7 +1253,6 @@
        *p = Resolve(reinterpret_cast<Address>(*p));
      }
    }
-  root_ = root;
  }





--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to