Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
8122ad7b
Commit
8122ad7b
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Simplify intern_dict
parent
2f0180b0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/util/caches/__init__.py
+10
-17
10 additions, 17 deletions
synapse/util/caches/__init__.py
with
10 additions
and
17 deletions
synapse/util/caches/__init__.py
+
10
−
17
View file @
8122ad7b
...
...
@@ -65,27 +65,20 @@ def intern_string(string):
def
intern_dict
(
dictionary
):
"""
Takes a dictionary and interns well known keys and their values
"""
return
_intern_known_values
({
_intern_key
(
key
):
value
for
key
,
value
in
dictionary
.
items
()
})
return
{
KNOWN_KEYS
.
get
(
key
,
key
):
_intern_known_values
(
key
,
value
)
for
key
,
value
in
dictionary
.
items
()
}
def
_intern_known_values
(
dictionary
):
def
_intern_known_values
(
key
,
value
):
intern_str_keys
=
(
"
event_id
"
,
"
room_id
"
)
intern_unicode_keys
=
(
"
sender
"
,
"
user_id
"
,
"
type
"
,
"
state_key
"
)
for
key
in
intern_str_keys
:
val
=
dictionary
.
get
(
key
,
None
)
if
val
is
not
None
:
dictionary
[
key
]
=
intern
(
val
.
encode
(
'
ascii
'
))
if
key
in
intern_str_keys
:
return
intern
(
value
.
encode
(
'
ascii
'
))
for
key
in
intern_unicode_keys
:
val
=
dictionary
.
get
(
key
,
None
)
if
val
is
not
None
:
dictionary
[
key
]
=
intern_string
(
val
)
if
key
in
intern_unicode_keys
:
return
intern_string
(
value
)
return
dictionary
def
_intern_key
(
key
):
return
KNOWN_KEYS
.
get
(
key
,
key
)
return
value
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment