'use strict'


/**
 * A fast clone function, which covers only the use case of Fortune.
 *
 * @param {*}
 * @return {*}
 */
module.exports = function clone (node) {
  var i, j, c, b, key, value, keys, isArray

  if (Array.isArray(node)) isArray = true
  else if (!node || Object.getPrototypeOf(node) !== Object.prototype)
    return node

  keys = Object.keys(node)
  c = isArray ? [] : {}

  for (i = 0, j = keys.length; i < j; i++) {
    key = keys[i]
    value = node[key]
    if (value &&
      Object.getPrototypeOf(value) === Object.prototype ||
      Array.isArray(value))
      c[key] = clone(value)
    else if (Buffer.isBuffer(value)) {
      b = new Buffer(value.length)
      value.copy(b)
      c[key] = b
    }
    else if (value instanceof Date)
      c[key] = new Date(value)
    else c[key] = value
  }

  return c
}

@@ -326,20 +326,32 @@
  return 
+cloneValue(
 node
+)
 %0A%0A  keys
@@ -485,20 +485,25 @@
 ey%5D%0A    
-if (
+c%5Bkey%5D = 
 value &&
@@ -592,46 +592,109 @@
 lue)
-)%0A      c%5Bkey%5D = clone
+ ? clone(value) : cloneValue(value)%0A  %7D%0A%0A  return c%0A%7D%0A%0A%0Afunction cloneValue 
 (value)
+ %7B
 %0A  
-  else
+var buffer%0A%0A 
  if 
@@ -728,11 +728,14 @@
     
-  b
+buffer
  = n
@@ -762,18 +762,16 @@
 th)%0A    
-  
 value.co
@@ -778,41 +778,39 @@
 py(b
-)%0A      c%5Bkey%5D = b%0A 
+uffer)%0A    return buffer%0A
   
- 
 %7D%0A
+%0A
  
-   else
  if 
@@ -837,26 +837,22 @@
 te)%0A    
-  c%5Bkey%5D =
+return
  new Dat
@@ -863,36 +863,8 @@
 lue)
-%0A    else c%5Bkey%5D = value%0A  %7D
 %0A%0A  
@@ -862,20 +862,24 @@
 alue)%0A%0A  return 
-c
+value
 %0A%7D%0A

revise clone implementation