src/Pure/PIDE/xml.scala
changeset 73024 337e1b135d2f
parent 71601 97ccf48c2f0c
child 73028 95e0f014cd24
equal deleted inserted replaced
73023:e15621aa8c72 73024:337e1b135d2f
   168 
   168 
   169 
   169 
   170 
   170 
   171   /** cache **/
   171   /** cache **/
   172 
   172 
   173   def make_cache(initial_size: Int = 131071, max_string: Int = 100): Cache =
   173   object Cache
   174     new Cache(initial_size, max_string)
   174   {
   175 
   175     def make(
   176   class Cache private[XML](initial_size: Int, max_string: Int)
   176         max_string: Int = isabelle.Cache.default_max_string,
   177     extends isabelle.Cache(initial_size, max_string)
   177         initial_size: Int = isabelle.Cache.default_initial_size): Cache =
       
   178       new Cache(max_string, initial_size)
       
   179 
       
   180     val none: Cache = make(max_string = 0)
       
   181   }
       
   182 
       
   183   class Cache private[XML](max_string: Int, initial_size: Int)
       
   184     extends isabelle.Cache(max_string, initial_size)
   178   {
   185   {
   179     protected def cache_props(x: Properties.T): Properties.T =
   186     protected def cache_props(x: Properties.T): Properties.T =
   180     {
   187     {
   181       if (x.isEmpty) x
   188       if (x.isEmpty) x
   182       else
   189       else
   220           case None => x.map(cache_tree)
   227           case None => x.map(cache_tree)
   221         }
   228         }
   222     }
   229     }
   223 
   230 
   224     // main methods
   231     // main methods
   225     def props(x: Properties.T): Properties.T = synchronized { cache_props(x) }
   232     def props(x: Properties.T): Properties.T =
   226     def markup(x: Markup): Markup = synchronized { cache_markup(x) }
   233       if (no_cache) x else synchronized { cache_props(x) }
   227     def tree(x: XML.Tree): XML.Tree = synchronized { cache_tree(x) }
   234     def markup(x: Markup): Markup =
   228     def body(x: XML.Body): XML.Body = synchronized { cache_body(x) }
   235       if (no_cache) x else synchronized { cache_markup(x) }
   229     def elem(x: XML.Elem): XML.Elem = synchronized { cache_tree(x).asInstanceOf[XML.Elem] }
   236     def tree(x: XML.Tree): XML.Tree =
       
   237       if (no_cache) x else synchronized { cache_tree(x) }
       
   238     def body(x: XML.Body): XML.Body =
       
   239       if (no_cache) x else synchronized { cache_body(x) }
       
   240     def elem(x: XML.Elem): XML.Elem =
       
   241       if (no_cache) x else synchronized { cache_tree(x).asInstanceOf[XML.Elem] }
   230   }
   242   }
   231 
   243 
   232 
   244 
   233 
   245 
   234   /** XML as data representation language **/
   246   /** XML as data representation language **/