| OLD | NEW |
| 1 # Copyright 2014 Google Inc. All rights reserved. | 1 # Copyright 2014 Google Inc. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """A clone of the default copy.deepcopy that doesn't handle cyclic | 5 """A clone of the default copy.deepcopy that doesn't handle cyclic |
| 6 structures or complex types except for dicts and lists. This is | 6 structures or complex types except for dicts and lists. This is |
| 7 because gyp copies so large structure that small copy overhead ends up | 7 because gyp copies so large structure that small copy overhead ends up |
| 8 taking seconds in a project the size of Chromium.""" | 8 taking seconds in a project the size of Chromium.""" |
| 9 | 9 |
| 10 class Error(Exception): | 10 class Error(Exception): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return _deepcopy_dispatch[type(x)](x) | 21 return _deepcopy_dispatch[type(x)](x) |
| 22 except KeyError: | 22 except KeyError: |
| 23 raise Error('Unsupported type %s for deepcopy. Use copy.deepcopy ' + | 23 raise Error('Unsupported type %s for deepcopy. Use copy.deepcopy ' + |
| 24 'or expand simple_copy support.' % type(x)) | 24 'or expand simple_copy support.' % type(x)) |
| 25 | 25 |
| 26 _deepcopy_dispatch = d = {} | 26 _deepcopy_dispatch = d = {} |
| 27 | 27 |
| 28 def _deepcopy_atomic(x): | 28 def _deepcopy_atomic(x): |
| 29 return x | 29 return x |
| 30 | 30 |
| 31 for x in (type(None), int, long, float, | 31 try: |
| 32 bool, str, unicode, type): | 32 _string_types = (str, unicode) |
| 33 # There's no unicode in python3 |
| 34 except NameError: |
| 35 _string_types = (str, ) |
| 36 |
| 37 try: |
| 38 _integer_types = (int, long) |
| 39 # There's no long in python3 |
| 40 except NameError: |
| 41 _integer_types = (int, ) |
| 42 |
| 43 for x in (type(None), float, bool, type) + _integer_types + _string_types: |
| 33 d[x] = _deepcopy_atomic | 44 d[x] = _deepcopy_atomic |
| 34 | 45 |
| 35 def _deepcopy_list(x): | 46 def _deepcopy_list(x): |
| 36 return [deepcopy(a) for a in x] | 47 return [deepcopy(a) for a in x] |
| 37 d[list] = _deepcopy_list | 48 d[list] = _deepcopy_list |
| 38 | 49 |
| 39 def _deepcopy_dict(x): | 50 def _deepcopy_dict(x): |
| 40 y = {} | 51 y = {} |
| 41 for key, value in x.iteritems(): | 52 for key, value in x.items(): |
| 42 y[deepcopy(key)] = deepcopy(value) | 53 y[deepcopy(key)] = deepcopy(value) |
| 43 return y | 54 return y |
| 44 d[dict] = _deepcopy_dict | 55 d[dict] = _deepcopy_dict |
| 45 | 56 |
| 46 del d | 57 del d |
| OLD | NEW |