mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #19846 -- Optimized a dict of lists in BlockContext class
Thanks Curtis Maloney for the report and the patch.
This commit is contained in:
		| @@ -1,3 +1,5 @@ | ||||
| from collections import defaultdict | ||||
|  | ||||
| from django.conf import settings | ||||
| from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\ | ||||
|     token_kwargs, Variable | ||||
| @@ -15,19 +17,16 @@ class ExtendsError(Exception): | ||||
| class BlockContext(object): | ||||
|     def __init__(self): | ||||
|         # Dictionary of FIFO queues. | ||||
|         self.blocks = {} | ||||
|         self.blocks = defaultdict(list) | ||||
|  | ||||
|     def add_blocks(self, blocks): | ||||
|         for name, block in six.iteritems(blocks): | ||||
|             if name in self.blocks: | ||||
|             self.blocks[name].insert(0, block) | ||||
|             else: | ||||
|                 self.blocks[name] = [block] | ||||
|  | ||||
|     def pop(self, name): | ||||
|         try: | ||||
|             return self.blocks[name].pop() | ||||
|         except (IndexError, KeyError): | ||||
|         except IndexError: | ||||
|             return None | ||||
|  | ||||
|     def push(self, name, block): | ||||
| @@ -36,7 +35,7 @@ class BlockContext(object): | ||||
|     def get_block(self, name): | ||||
|         try: | ||||
|             return self.blocks[name][-1] | ||||
|         except (IndexError, KeyError): | ||||
|         except IndexError: | ||||
|             return None | ||||
|  | ||||
| class BlockNode(Node): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user