deepcopy() is extremely slow

Actually, deepcopy is very slow. But we can use json, ujson, or cPickle. we can use json/cPickle to dump an object, and load it later. This is my test: Total time: 3.46068 s File: test_deepcopy.py Function: test at line 15 Line # Hits Time Per Hit % Time Line Contents ============================================================== 15 @profile 16 def … Read more

Deep copying a PSObject

Note that here is a shorter, maybe a bit cleaner version of this (that I quite enjoy): $data = Import-Csv .\test.csv $serialData = [System.Management.Automation.PSSerializer]::Serialize($data) $data2 = [System.Management.Automation.PSSerializer]::Deserialize($serialData) Note: However, weirdly, it does not keep the ordering of ordered hashtables. $data = [ordered] @{ 1 = 1 2 = 2 } $serialData = [System.Management.Automation.PSSerializer]::Serialize($data) $data2 = … Read more

Shallow copy or Deep copy?

From the link here Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements. Deep copies duplicate everything. A deep copy of a collection is two collections with all of the … Read more

Deep copy of dictionaries gives Analyze error in Xcode 4.2

Presumably, it is because deepCopy does not begin with the prefix copy. So you may want to change to something like copyWithDeepCopiedValues (or something like that), and then see if the analyzer flags that. Update As Alexsander noted, you can use attributes to denote reference counting intent. This should (IMO) be the exception to the … Read more

Does Object.assign() create a deep copy or a shallow copy?

Forget about deep copy, even shallow copy isn’t safe, if the object you’re copying has a property with enumerable attribute set to false. MDN : The Object.assign() method only copies enumerable and own properties from a source object to a target object take this example var o = {}; Object.defineProperty(o,’x’,{enumerable: false,value : 15}); var ob={}; … Read more