Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
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
Branches containing commit
No related tags found
Tags containing commit
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):
...
@@ -65,27 +65,20 @@ def intern_string(string):
def
intern_dict
(
dictionary
):
def
intern_dict
(
dictionary
):
"""
Takes a dictionary and interns well known keys and their values
"""
Takes a dictionary and interns well known keys and their values
"""
"""
return
_intern_known_values
({
return
{
_intern_key
(
key
):
value
for
key
,
value
in
dictionary
.
items
()
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_str_keys
=
(
"
event_id
"
,
"
room_id
"
)
intern_unicode_keys
=
(
"
sender
"
,
"
user_id
"
,
"
type
"
,
"
state_key
"
)
intern_unicode_keys
=
(
"
sender
"
,
"
user_id
"
,
"
type
"
,
"
state_key
"
)
for
key
in
intern_str_keys
:
if
key
in
intern_str_keys
:
val
=
dictionary
.
get
(
key
,
None
)
return
intern
(
value
.
encode
(
'
ascii
'
))
if
val
is
not
None
:
dictionary
[
key
]
=
intern
(
val
.
encode
(
'
ascii
'
))
for
key
in
intern_unicode_keys
:
if
key
in
intern_unicode_keys
:
val
=
dictionary
.
get
(
key
,
None
)
return
intern_string
(
value
)
if
val
is
not
None
:
dictionary
[
key
]
=
intern_string
(
val
)
return
dictionary
return
value
def
_intern_key
(
key
):
return
KNOWN_KEYS
.
get
(
key
,
key
)
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