
On Feb 8, 2013 12:29 PM, "Mathias Gaunard" <mathias.gaunard@ens-lyon.org> wrote:
On 08/02/13 18:35, Jeffrey Yasskin wrote:
WebKit has a class vaguely like this for your case #2:
https://code.google.com/p/chromium/codesearch/#chrome/src/third_party/WebKit...
used at https://code.google.com/p/chromium/codesearch/#chrome/src/third_party/WebKit/Source/WebCore/rendering/style/RenderStyle.h&rcl=1360310731&l=137 . Semantically every copy is a real copy, and, contrary to Mathias' assertion, couldn't be replaced by a move in C++11, but they want to share identical values when doing so is cheap.
If you want identical values to use the same resource, you should use a flyweight factory.
I'm sure the WebKit project would welcome a patch demonstrating that flyweights are a more efficient technique for CSS matching. I don't expect they are because these values are built up through several mutations, and a hash table lookup plus a copy on each mutation sounds more expensive than the current copy-on-write system. Jeffrey